404处理在Azure的网站 [英] 404 handling in Azure website
问题描述
我有在Azure上一个MVC网站。我写了一个控制器动作站在一个资源,应该返回HTTP 404,但主体内容应该是一些HTML,我解释了404这是因为,设置 Response.Status code
。这在当地工作正常,但在部署到Azure的,我没有得到我的自定义视图,而只是以纯文本的错误信息。我已删除<的customErrors方式>
在Azure上进行调试,具有相同的结果。
I have got an MVC website on Azure. I have written a controller action to stand in for a resource, that should return HTTP 404, but the body content should be some HTML where I explain the reason for the 404. This is implemented as a standard action that sets Response.StatusCode
. This works fine locally, but when deployed to Azure, I do not get my custom view, but just an error message in plain text. I have removed <customErrors>
on Azure for debugging, with the same result.
这是在部署到Azure中接收的原始响应:
This is the raw response received when deployed to Azure:
HTTP/1.1 404 Not Found
Cache-Control: private
Content-Length: 103
Content-Type: text/html
Server: Microsoft-IIS/8.0
X-AspNetMvc-Version: 3.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
X-Powered-By: ARR/2.5
X-Powered-By: ASP.NET
Date: Sat, 17 Aug 2013 17:24:19 GMT
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
同样重要的是,如果我删除这个服务的路线,我得到一个标准的.NET 404错误页面,所以我想我的自定义操作越来越运行。该行动就是直截了当:
Also important, if I remove the route serving this, I get a standard .NET 404 error page, so I guess my custom action is getting run. The action is just straight forward:
[HttpGet]
public ActionResult LegacyMedia(string originalUrl)
{
ViewBag.OriginalUrl = originalUrl;
return new ViewResult404() {ViewName = "LegacyMedia"};
}
public class ViewResult404 : ViewResult
{
public override void ExecuteResult(ControllerContext context)
{
context.HttpContext.Response.StatusCode = (int) HttpStatusCode.NotFound;
base.ExecuteResult(context);
}
}
如何才能让我的看法,而在Azure上响应HTTP状态404呈现?
How can I get my view rendered while responding HTTP Status 404 on Azure ?
推荐答案
我能加入这个httpErrors进入到Web.config来解决这个问题:
I was able to fix this by adding this httpErrors entry to the web.config:
<configuration>
<system.webServer>
<httpErrors existingResponse="PassThrough"/>
</system.webServer>
<configuration>
我在这里找到这个答案:
I found this answer here:
<一个href=\"http://blog.dezfowler.com/2010/09/aspnet-custom-error-not-shown-in-azure.html\">http://blog.dezfowler.com/2010/09/aspnet-custom-error-not-shown-in-azure.html
这篇关于404处理在Azure的网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!