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.

Filter by
Sorted by
Tagged with
580votes
15answers
402kviews

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 ...
user avatar
  • 11.3k
475votes
9answers
385kviews

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 ...
user avatar
  • 35.9k
442votes
34answers
289kviews

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 { } ...
user avatar
  • 25.1k
365votes
26answers
601kviews

ASP.NET Core Dependency Injection error: Unable to resolve service for type while attempting to activate

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 ...
user avatar
  • 10.5k
312votes
21answers
243kviews

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.
user avatar
  • 19k
294votes
18answers
167kviews

ASP.NET Core Get Json Array using IConfiguration

In appsettings.json { "MyArray": [ "str1", "str2", "str3" ] } In Startup.cs public void ConfigureServices(IServiceCollection services) { services....
user avatar
  • 3,649
293votes
15answers
153kviews

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 ...
user avatar
283votes
13answers
201kviews

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 : ...
user avatar
283votes
21answers
491kviews

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"...
user avatar
  • 3,660
282votes
10answers
272kviews

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(...
user avatar
252votes
19answers
326kviews

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.
user avatar
  • 3,380
209votes
7answers
274kviews

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<Employee> EmployeesList and ...
user avatar
  • 22.2k
183votes
14answers
77kviews

.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 ...
user avatar
  • 3,902
182votes
17answers
140kviews

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 ...
user avatar
  • 2,088
178votes
10answers
200kviews

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 ...
user avatar
  • 25.1k

15 30 50 per page
1
2 3 4 5
841