[英]401 and 403 Custom Error page not displaying when App deployed to Azure
我有一個 ASP.NET Core WebApp。 應用程序中的 AuthN 和 AuthZ 由 AAD 處理 - 如果用戶嘗試訪問站點中的頁面並且不在正確的 AAD 組中,我將嘗試使用中間件並呈現和 NotAuthorized 頁面。
在 Configure 方法的 Startup 類中,我有以下代碼:
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseWhen(context => !context.Request.Path.StartsWithSegments("/api"), appBuilder =>
{
appBuilder.UseStatusCodePagesWithReExecute("/Error/{0}");
appBuilder.UseExceptionHandler("/Error");
});
app.UseHsts();
}
對於本地 IIS 測試,我注釋掉了 if 塊並部署到我的本地 IIS,並且在我的 AppSettings 中只添加了一個我知道我不是成員的 AAD 組 - 當我在本地點擊 URL 時,我得到以下內容預計:
我的 ErrorController 中的代碼如下:
public class ErrorController : Controller
{
[Route("error/404")]
public IActionResult ErrorNotFound()
{
return View();
}
[Route("error/401")]
[Route("error/403")]
public IActionResult ErrorNotAuthorized()
{
return View();
}
[AllowAnonymous]
public IActionResult Index()
{
return View("Index", Activity.Current?.RootId);
}
}
但是,當我將相同的代碼部署到 Azure 時,當我點擊相同的 URL 時會得到以下信息 -
當我的應用程序部署到 Azure 時,為什么我的客戶 403 頁面沒有被呈現,我是否也遺漏了什么?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.