asp.net-core-mvc

How to access IConfigurationRoot in startup on .net core 2?

浪子不回头ぞ 提交于 2019-12-19 16:24:10
问题 I have written a custom ConfigurationProvider with the entity framework. Since I also want to make it updateable during runtime, I have created a IWritableableOption. I need to refresh the configuration after the update. This can be done via IConfigurationRoot.Reload. However, how can I get the IConfigurationRoot in .net core 2? What I have found, is that in previous versions the IConfigurationRoot was part of startup. In .net core 2 however, we have only the simpler type IConfiguration :

How to access IConfigurationRoot in startup on .net core 2?

独自空忆成欢 提交于 2019-12-19 16:23:27
问题 I have written a custom ConfigurationProvider with the entity framework. Since I also want to make it updateable during runtime, I have created a IWritableableOption. I need to refresh the configuration after the update. This can be done via IConfigurationRoot.Reload. However, how can I get the IConfigurationRoot in .net core 2? What I have found, is that in previous versions the IConfigurationRoot was part of startup. In .net core 2 however, we have only the simpler type IConfiguration :

How to get the current Windows user with ASP.NET Core RC2 MVC6 and IIS7

别等时光非礼了梦想. 提交于 2019-12-19 14:23:26
问题 I have an intranet site built in MVC6 using ASP.NET Core RC2. I want to get the Windows username of the person accessing the intranet site. So if Jim goes to the intranet site I want the site to receive "Domain\Jim", while if Anne goes to the intranet site I want the site to receive "Domain\Anne". Only Windows Authentication is enabled on my IIS server, Anonymous Authentication is disabled. My site is set to use Windows authentication and to disable anonymous authentication. <system.web>

How to get the current Windows user with ASP.NET Core RC2 MVC6 and IIS7

本小妞迷上赌 提交于 2019-12-19 14:23:16
问题 I have an intranet site built in MVC6 using ASP.NET Core RC2. I want to get the Windows username of the person accessing the intranet site. So if Jim goes to the intranet site I want the site to receive "Domain\Jim", while if Anne goes to the intranet site I want the site to receive "Domain\Anne". Only Windows Authentication is enabled on my IIS server, Anonymous Authentication is disabled. My site is set to use Windows authentication and to disable anonymous authentication. <system.web>

Get the full route to current action

南笙酒味 提交于 2019-12-19 12:23:15
问题 I have a simple API with basic routing. It was setup using the default Visual Studio 2015 ASP.NET Core API template. I have this controller and action: [Route("api/[controller]")] public class DocumentController : Controller { [HttpGet("info/{Id}")] public async Task<Data> Get(string Id) { //Logic } } So to reach this method, I must call GET /api/document/info/some-id-here . Is it possible with .NET Core, inside that method, to retrieve as a string the complete route? So I could do for

Localization in Asp.Net Core

我的梦境 提交于 2019-12-19 10:08:10
问题 I have been following the instructions on this page to setup Localization: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization However, for me it just doesn't seem to work. Here is what I have done: Startup.cs: public class Startup { public IConfigurationRoot Configuration { get; } public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", true, true); builder.AddEnvironmentVariables(

How can pass data from AuthorizationHandler to Controller in Asp.net core

走远了吗. 提交于 2019-12-19 09:59:13
问题 I used a specific authorization policy for user log in, so created custom Authorization Handler. And I would like to display use a specific alert message if they failed the policy. I read the documentation and found that I could access AuthorizationFilterContext via casting AuthorizationHandlerContext. I tried to add message to HttpContext.Items property and access it in my controller, but it returns false when i check it with TryGetValue method. if (context.HasFailed && context.Resource is

How can pass data from AuthorizationHandler to Controller in Asp.net core

倾然丶 夕夏残阳落幕 提交于 2019-12-19 09:58:09
问题 I used a specific authorization policy for user log in, so created custom Authorization Handler. And I would like to display use a specific alert message if they failed the policy. I read the documentation and found that I could access AuthorizationFilterContext via casting AuthorizationHandlerContext. I tried to add message to HttpContext.Items property and access it in my controller, but it returns false when i check it with TryGetValue method. if (context.HasFailed && context.Resource is

Oauth2 login to Google api with ASP .net core MVC

谁都会走 提交于 2019-12-19 09:51:05
问题 I have been following Web applications (ASP.NET MVC) Attempting to connect to one of the Google APIs. using System; using System.Web.Mvc; using Google.Apis.Auth.OAuth2; using Google.Apis.Auth.OAuth2.Flows; using Google.Apis.Auth.OAuth2.Mvc; using Google.Apis.Drive.v2; using Google.Apis.Util.Store; namespace Google.Apis.Sample.MVC4 { public class AppFlowMetadata : FlowMetadata { private static readonly IAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow(new

Where can you find model binding errors in ASP.NET Core MVC?

非 Y 不嫁゛ 提交于 2019-12-19 09:27:22
问题 When performing model binding to objects, it seems that the framework will return null if there are type mismatches for any of the object's properties. For instance, consider this simple example: public class Client { public string Name { get; set; } public int Age { get; set; } public DateTime RegistrationDate { get; set; } } public class ClientController : Controller { [HttpPatch] public IActionResult Patch([FromBody]Client client) { return Ok("Success!"); } } If I submit a value of "asdf"