首页 > 解决方案 > 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.

标签: c#asp.net-core

解决方案


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

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

推荐阅读