asp.net-core-middleware

In asp.net core, why is await context.ChallengeAsync() not working as expected?

﹥>﹥吖頭↗ 提交于 2019-12-25 01:46:53
问题 I have two questions, both of which refer to the code below: Why is authenticateResult.Succeeded false after I call authenticateResult = await context.AuthenticateAsync();? Why do I need to call "return" from my custom middleware InvokeAsync method for this to work properly? I have an asp.net core application using OpenIdConnect. The application has two controller actions; both of them have the [Authorize] attribute, so when the application starts the user is automatically put through the

How to distribute razor views to another application in .NET Core

本秂侑毒 提交于 2019-12-24 10:13:45
问题 I have created web application - Asp.Net MVC in .NET Core . This application contains some Razor Views but I would like to share these views to another application like for example with DLL or like middleware. Here is some information about example with distribution Controllers but around Views nothing special - https://docs.microsoft.com/en-us/aspnet/core/mvc/advanced/app-parts I've tried add Controller like this: var assembly = typeof(Project.HomeController).GetTypeInfo().Assembly; services

Angular 2 AspNetCore WebApi CORS issue: Response for preflight has invalid HTTP status code 401

穿精又带淫゛_ 提交于 2019-12-23 15:44:18
问题 I am attempting to implement simple token based authentication in an Angular 2 RC6 application against an AspNetCore WebApi project that I've implemented in Visual Studio 2015. I have put my sample application on github at: https://github.com/tonywr71/Snazzle which is a fully functioning application. In the application, I click on the Login menu item, put in login and password information then click login. It successfully returns am authentication token, which I store in isolated storage. I

Stackify Prefix doesn't collect any data in ASP.NET Core

十年热恋 提交于 2019-12-22 04:32:09
问题 I tried Prefix from Stackify as an alternative to Glimpse, which doesn't support native ASP.NET Core. According to this article and the docs, I installed the server application using chocolately. Then installed the NuGet-Package StackifyMiddleware and activated it in the Configure method - bevor MVC is added, like mentioned in the official docs. Finally, I activated .NET profiling using the tray icon and re-opened Visual Studio. The browser opened the data overview page of Prefix (http:/

Request content decompression in ASP.Net Core

我们两清 提交于 2019-12-21 06:50:16
问题 I sometimes need to post larger JSON request payloads to my ASP.Net Core Controllers. The size of the payload warrants (at least in my opinion) compressing it. Because ASP.Net Core Controllers do not appear to support compressed request content out of the box, I've rolled my own middleware. Implementing this was so trivial that I'm not sure if I'm missing something here. Either because there's a built-in way to achieve this or because I made some major mistake from a security- or performance

Read JSON post data in ASP.Net Core MVC

有些话、适合烂在心里 提交于 2019-12-18 19:17:08
问题 I've tried to find a solution for this, but all the ones coming up are for previous versions of ASP.Net. I'm working with the JWT authentication middleware and have the following method: private async Task GenerateToken(HttpContext context) { var username = context.Request.Form["username"]; var password = context.Request.Form["password"]; //Remainder of login code } This gets the sent data as if it was form data, but my Angular 2 front end is sending the data as JSON. login(username: string,

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

Exception-Handling Middleware and Page

巧了我就是萌 提交于 2019-12-18 07:52:33
问题 I'm new to the concept of middleware, and am currently struggling with the proper way to handle exceptions in my MVC Core project. What I want to happen is for the Exception to be caught, logged, and then send the user to a friendly error page with a message. At first, I was trying to manage all of these within the middleware, but realized I probably wasn't doing it correctly. So if I want this flow to happen, should I use both my Exception-logging middleware AND the app.UseExceptionHandler("

ASP NET Core modify/substitute a request body

て烟熏妆下的殇ゞ 提交于 2019-12-18 05:47:14
问题 I need to do the substitution of HttpContext.Request.Body. I've tried to do it inside middleware public async Task Invoke(HttpContext context) { if (context.Request.Path.Value.Contains("DataSourceResult")) { var originalBody = new StreamReader(context.Request.Body).ReadToEnd(); DataSourceRequest dataSource = null; try { dataSource = JsonConvert.DeserializeObject<DataSourceRequest>(originalBody); } catch { await _next.Invoke(context); } if (dataSource != null && dataSource.Take > 2000) {

ASP.NET Core Web Api Middleware Custom Exception

会有一股神秘感。 提交于 2019-12-13 20:14:16
问题 ASP.NET Core Web Api Middleware Converts Custom Exception into Base Exception I have created a custom exception class and use it throw an exception. The middleware catches it but throws base exception instead of custom exception. I am not able to understand why it does not catch custom exception. Custom Exception public class CustomException : Exception { public int HttpStatusCode { get; private set; } public CustomException() { } public CustomException(int httpStatusCode, string message)