我試圖提高我網站的安全性,我嘗試過的一件事是當用戶不是管理員并且想要訪問管理頁面時,系統回傳NotFound。這使得黑客不可能知道您的管理頁面。但是怎么做呢?這是我嘗試過的。我在 program.cs 中制作了一個中間件來檢查 URL 并在某處重定向,這不是我想要的。即使我嘗試將狀態碼設定為 404,但這不起作用。我想在這里訪問的是return NotFound ();方法。有沒有辦法做到這一點。謝謝
app.Use (async (context, next) =>
{
if (context.Request.Path.StartsWithSegments ("/Admin"))
{
if (/* Checking if user is not admin */)
{
// context.Response.Redirect ("/");
// The code to do same as return NotFound ();
}
}
await next.Invoke ();
});
uj5u.com熱心網友回復:
// Write response
context.Response.StatusCode = ((int)HttpStatusCode.NotFound);
return;
uj5u.com熱心網友回復:
還有一種更好的方法我意識到不需要使用 Microsoft.Net:
context.Response.StatusCode = 404;
return;
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/447385.html
