2017-04-20 18 views
0

我正在研究.Net核心Web應用程序,我們希望能夠將一種類型的URL重定向到我們的自定義錯誤頁面。該網站託管在Azure上,似乎該錯誤未在應用程序中處理。下面是URL的我一起工作的類型:重定向在應用程序外部結束

www.mywebsite.com/%22http://www.yahoo.com/%22 

時出現的錯誤頁面如下:

The page cannot be displayed because an internal server error has occurred. 

另外當我檢查在Azure上的活HTTP流量不顯示發生錯誤。

編輯: 蔚藍顯然無法處理這種類型的請求都:https://azure.microsoft.com/%22/http://www.google.com/

它看起來第二URL中的配置文件。有誰知道我可以在哪裏提交微軟的錯誤?

回答

0

我沒有在Azure上測試過它,但它在我們的服務器上工作。

Startup類中配置異常處理。

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 
{ 
    // ... 
    if (env.IsDevelopment()) 
    { 
     app.UseDeveloperExceptionPage(); 
    } 
    else 
    { 
     app.UseExceptionHandler("/error"); 
    } 
    // ... 
    app.UseStatusCodePagesWithRedirects("/error/{0}"); 
    // ... 
} 

和錯誤控制器。

[Route("[controller]")] 
public class ErrorController : Controller 
{ 
    [Route("")] 
    public IActionResult Index() 
    { 
     return View(); 
    } 

    [Route("{httpStatusCode}")] 
    public IActionResult Index(int httpStatusCode) 
    { 
     // handle by error code 
     switch (httpStatusCode) 
     { 
      case (int)HttpStatusCode.NotFound: 
       return View("NotFound"); 
      default: 
       return View(); 
     } 
    } 
} 
相關問題