Questions tagged [asp.net-core-mvc]

ASP.NET Core MVC is a lightweight presentation framework for creating dynamic websites with ASP.NET Core. It allows for creating controller based MVC sites, or view model based Razor pages. MVC includes features like routing, model binding and validation, filters, web APIs and the Razor view engine.

ASP.NET Core MVC is the primary way of creating dynamic websites with ASP.NET Core. It comes built-in with ASP.NET Core and includes capabilities for controller based MVC sites or view model based Razor pages (starting with ASP.NET Core 2).

Originally based on ASP.NET MVC and ASP.NET Web API, it has been redesigned from the ground up to unify the various frameworks into a single MVC framework in ASP.NET Core.

As an integral part of ASP.NET Core, its release cycle is bound to release of the main framework.

See also:

14278 questions
644
votes
18 answers

How do you create a custom AuthorizeAttribute in ASP.NET Core?

I'm trying to make a custom authorization attribute in ASP.NET Core. In previous versions it was possible to override bool AuthorizeCore(HttpContextBase httpContext). But this no longer exists in AuthorizeAttribute. What is the current approach to…
jltrem
  • 12,124
  • 4
  • 40
  • 50
573
votes
9 answers

Resolving instances with ASP.NET Core DI from within ConfigureServices

How do I manually resolve a type using the ASP.NET Core MVC built-in dependency injection framework? Setting up the container is easy enough: public void ConfigureServices(IServiceCollection services) { // ... …
Dave New
  • 38,496
  • 59
  • 215
  • 394
548
votes
38 answers

How to register multiple implementations of the same interface in Asp.Net Core?

I have services that are derived from the same interface. public interface IService { } public class ServiceA : IService { } public class ServiceB : IService { } public class ServiceC : IService { } Typically, other IoC containers like Unity allow…
LP13
  • 30,567
  • 53
  • 217
  • 400
493
votes
30 answers

Dependency Injection error: Unable to resolve service for type while attempting to activate, while class is registered

I created an .NET Core MVC application and use Dependency Injection and Repository Pattern to inject a repository to my controller. However, I am getting an error: InvalidOperationException: Unable to resolve service for type…
kimbaudi
  • 13,655
  • 9
  • 62
  • 74
393
votes
26 answers

How do I get client IP address in ASP.NET Core?

Can you please let me know how to get client IP address in ASP.NET when using MVC 6. Request.ServerVariables["REMOTE_ADDR"] does not work.
eadam
  • 23,151
  • 18
  • 48
  • 71
360
votes
20 answers

ASP.NET Core Get Json Array using IConfiguration

In appsettings.json { "MyArray": [ "str1", "str2", "str3" ] } In Startup.cs public void ConfigureServices(IServiceCollection services) { services.AddSingleton(Configuration); } In…
Max
  • 4,439
  • 2
  • 18
  • 32
349
votes
16 answers

How to get the Development/Staging/production Hosting Environment in ConfigureServices

How do I get the Development/Staging/production Hosting Environment in the ConfigureServices method in Startup? public void ConfigureServices(IServiceCollection services) { // Which environment are we running under? } The ConfigureServices…
Muhammad Rehan Saeed
  • 35,627
  • 39
  • 202
  • 311
338
votes
16 answers

ASP.NET Core form POST results in a HTTP 415 Unsupported Media Type response

Sending a form POST HTTP request (Content-Type: application/x-www-form-urlencoded) to the below controller results into a HTTP 415 Unsupported Media Type response. public class MyController : Controller { [HttpPost] public async…
Bart Verkoeijen
  • 16,545
  • 7
  • 52
  • 56
331
votes
24 answers

Getting value from appsettings.json in .net core

Not sure what am I missing here but I am not able to get the values from my appsettings.json in my .net core application. I have my appsettings.json as: { "AppSettings": { "Version": "One" } } Startup: public class Startup { …
aman
  • 4,198
  • 4
  • 24
  • 36
328
votes
12 answers

How to return HTTP 500 from ASP.NET Core RC2 Web Api?

Back in RC1, I would do this: [HttpPost] public IActionResult Post([FromBody]string something) { try{ // ... } catch(Exception e) { return new HttpStatusCodeResult((int)HttpStatusCode.InternalServerError); …
Mickael Caruso
  • 8,721
  • 11
  • 40
  • 72
285
votes
23 answers

How to get the current logged in user ID in ASP.NET Core?

I've done this before with MVC5 using User.Identity.GetUserId() but that doesn't seem to work here. The User.Identity doesn't have the GetUserId() method. I am using Microsoft.AspNet.Identity.
MRainzo
  • 3,800
  • 2
  • 16
  • 25
234
votes
17 answers

.NET Core MVC Page Not Refreshing After Changes

I'm building a .NET Core MVC on the latest version 2.2. I have a problem when I make changes to the CSHTML file and refresh the page, my changes are not reflected in the browser. I have to restart the project in order to see my changes. This has…
kevskree
  • 4,442
  • 3
  • 24
  • 32
228
votes
7 answers

Select Tag Helper in ASP.NET Core MVC

I need some help with the select tag helper in ASP.NET Core. I have a list of employees that I'm trying to bind to a select tag helper. My employees are in a List EmployeesList and selected value will go into EmployeeId property. My view…
Sam
  • 26,817
  • 58
  • 206
  • 383
215
votes
11 answers

How do I access Configuration in any class in ASP.NET Core?

I have gone through configuration documentation on ASP.NET core. Documentation says you can access configuration from anywhere in the application. Below is Startup.cs created by template public class Startup { public Startup(IHostingEnvironment…
LP13
  • 30,567
  • 53
  • 217
  • 400
209
votes
17 answers

Publish to IIS, setting Environment Variable

Reading these two questions/answers I was able to run an Asp.net 5 app on IIS 8.5 server. Asp.net vNext early beta publish to IIS in windows server How to configure an MVC6 app to work on IIS? The problem is that the web app is still using…
drpdrp
  • 2,351
  • 3
  • 11
  • 15
1
2 3
99 100