c# - 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, e.g.:
app.UseWhen(context => !context.Request.Path.ToString().Contains("ActionToOmit"), appBuilder =>
{
appBuilder.UseApiResponseWrapper();
});
推荐阅读
- html - 将 PNG 图像放置在 div 轮播中
- python - 使用 smtplib 发送的电子邮件以垃圾邮件结尾
- oracle - 在 ORACLE 中从 SYS 向 USER 授予权限时出错
- swift - 在我继续 Swift 5 中的程序之前,我如何“等”到用户开始实际移动?
- sql - 在 SQL Server 中添加一个新列,随机数介于 1 到 5 之间
- javascript - 为什么 every() 方法返回 false
- android - 我们可以在 android 中推送 .so 文件,因此无需与应用程序集成
- mql4 - 智能交易系统未开仓
- python - 关键字与字典中的函数相结合
- pandas - 分组后如何分别获取计数