我在Azure上有一个MVC网站。我已经写了一个控制器操作来代表资源,该资源应该返回HTTP 404,但是主体内容应该是一些HTML,我在其中解释了404的原因。这是作为set的标准操作实现的Response.StatusCode
。这在本地工作正常,但是当部署到Azure时,我没有获得自定义视图,而只是一条纯文本错误消息。我已<customErrors>
在Azure上删除调试,结果相同。
这是部署到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错误页面,因此我想我的自定义操作正在运行。动作很简单:
[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 Status 404时如何呈现视图?
我可以通过将以下httpErrors条目添加到web.config中来解决此问题:
<configuration>
<system.webServer>
<httpErrors existingResponse="PassThrough"/>
</system.webServer>
<configuration>
我在这里找到了这个答案:
http://blog.dezfowler.com/2010/09/aspnet-custom-error-not-shown-in-azure.html
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句