asp.net-core-2.0

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

DbContext Dependency Injection outside of MVC project

别等时光非礼了梦想. 提交于 2019-12-19 09:54:13
问题 I have a C# solution with two projects, ProductStore.Web and ProductStore.Data, both targeting .NET Core 2.0. I have my HomeController and CustomerRepository as follows (I've set it up in the HomeController for speed, customer creation will be in the customer controller, but not yet scaffold-ed it out): namespace ProductStore.Web.Controllers { public class HomeController : Controller { private readonly DatabaseContext _context; public HomeController(DatabaseContext context) { _context =

HTTP Error 502.5 - Process Failure asp.net core 2.0

纵然是瞬间 提交于 2019-12-19 09:23:27
问题 Problem I already developed my web app and published it to azure with asp.net core 1.1 and it was working fine until I upgraded my web application to Core 2.0 final release and now the app working locally but when I deploy it to Azure It gives me this issue . <ItemGroup> <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" /> </ItemGroup> I just update .csproj file with this line of code HTTP Error 502.5 - Process Failure Common causes of this issue: The application process

How to manage ASP.NET Core bundleconfig.json for multiple environments?

孤人 提交于 2019-12-19 02:47:36
问题 What's the best practice for using the ASP.NET Core bundleconfig.json with development versus production environments? The prior bundler (BundleCollection) would pay attention to the DEBUG compiler directive and not minify the list of scripts when you're debugging. It appears as though the new paradigm is to have <environment> tags in the HTML templates that test for the ASPNETCORE_ENVIRONMENT value. Though I don't see a way of incorporating that environment variable into the bundleconfig

Accept x-www-form-urlencoded in Web API .Net Core

孤街醉人 提交于 2019-12-18 21:52:38
问题 I have a .Net Core Web API that is returning a 415 Unsupported Media Error when I try to post some data to it that includes some json. Here's part of what is returned in the Chrome Debugger: Request URL:http://localhost:51608/api/trackAllInOne/set Request Method:POST Status Code:415 Unsupported Media Type Accept:text/javascript, text/html, application/xml, text/xml, */* Content-Type:application/x-www-form-urlencoded action:finish currentSco:CSharp-SSLA:__How_It_Works_SCO data:{"status":

ASP.Net Core 2.0 - How to return custom json or xml response from middleware?

可紊 提交于 2019-12-18 17:25:14
问题 In ASP.Net Core 2.0, I am trying to return a message formatted as json or xml with a status code. I have no problems returning a custom message from a controller, but I don't know how to deal with it in a middleware. My middleware class looks like this so far: public class HeaderValidation { private readonly RequestDelegate _next; public HeaderValidation(RequestDelegate next) { _next = next; } public async Task Invoke(HttpContext httpContext) { // How to return a json or xml formatted custom

Cannot find module 'aspnet-webpack' when using 'dotnet publish' in .Net Core 2.0 & Angular

纵饮孤独 提交于 2019-12-18 14:43:13
问题 I have been trying to follow answers to this problem but to no avail.. I am trying to publish my .Net Core 2.0 & Angular project using the command line command 'dotnet publish' I successfully publish, however when trying to run my project's .dll in the published folder, my project spits in out this error when run in a development environment: Unhandled Exception: System.AggregateException: One or more errors occurred. (Webpack dev middleware failed because of an error while loading 'aspnet

Cannot find module 'aspnet-webpack' when using 'dotnet publish' in .Net Core 2.0 & Angular

点点圈 提交于 2019-12-18 14:43:07
问题 I have been trying to follow answers to this problem but to no avail.. I am trying to publish my .Net Core 2.0 & Angular project using the command line command 'dotnet publish' I successfully publish, however when trying to run my project's .dll in the published folder, my project spits in out this error when run in a development environment: Unhandled Exception: System.AggregateException: One or more errors occurred. (Webpack dev middleware failed because of an error while loading 'aspnet

ASP.Net Core 2.0 - ResponseCaching Middleware - Not Caching on Server

独自空忆成欢 提交于 2019-12-18 13:25:51
问题 I want to use server-side response caching (output cache) with asp.net core 2.0 and found out about Response Caching Middleware and wanted to give it a try with a brand new asp.core mvc project. Here is the description from the link above which makes me think this could be used like output cache. The middleware determines when responses are cacheable, stores responses, and serves responses from cache. Here is how my startup.cs looks like. public class Startup { public Startup(IConfiguration

Microsoft.AspNetCore.Antiforgery was not found

蹲街弑〆低调 提交于 2019-12-18 07:32:10
问题 I'm deploying a asp.net core 2.0 website to IIS 10. I've made sure that my app is using the correct configuration for ISS in the program.settings file. public class Program { public static void Main(string[] args) { BuildWebHost(args).Run(); } public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup<Startup>() .Build(); } And in my startup.cs file: public void