![](/img/trans.png)
[英]How to fix error 404 when logging out on an ASP.NET Core MVC app against Azure AD?
[英]Redirection is not working when there is 404 error in ASP.NET Core MVC
當出現 404 錯誤時,我想將用戶重定向到操作方法頁面。 例如,我的域是www.test.com
,但是當用戶導航到www.test.com/abc/def
時,我想將用戶重定向到特定的 404 頁面。
這是我在program.cs
中的代碼:
app.Use(async (context, next) =>
{
EnteredPath = context.Request.HttpContext.Request.Path.ToString().Remove(0, 1);
await next();
if (context.Response.StatusCode == 404)
{
context.Request.Path="/URL/checkRawUrl";
await next();
}
});
它不起作用 - 我的 controller 名稱是URL
,操作名稱是checkRawUrl
。
感謝和問候
注意它必須在路由配置之前添加,如 app.UseRouting();.... 請檢查它。
app.Use(async (context, next) =>
{
string EnteredPath = context.Request.HttpContext.Request.Path.ToString().Remove(0, 1);
await next();
if (context.Response.StatusCode == 404)
{
context.Request.Path = "/URL/checkRawUrl";
await next();
}
});
app.UseRouting();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.