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.
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.
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);
}
}
How can I get my view rendered while responding HTTP Status 404 on Azure ?