简体   繁体   中英

How to return view in .NET Core when configuration set to app.UseAPIResponseWrapper() in startup.cs file

View is returning 500 status code when app.UseApiResponseWrapper() is added in startup.cs file.

I want to return View when controller action method hits for particular one action method and for remaining action methods app.UseApiResponseWrapper() should apply.

How can I omit app.UseApiResponseWrapper() for particular action method.

You can use Conditional middleware with UseWhen logic, wrap your app.UseApiResponseWrapper() with condition, eg:

app.UseWhen(context => !context.Request.Path.ToString().Contains("ActionToOmit"), appBuilder =>
{
    appBuilder.UseApiResponseWrapper();
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM