Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

404 handling in Azure website

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 ?

like image 490
driis Avatar asked Aug 17 '13 17:08

driis


People also ask

Can we host PHP website on Azure?

Azure App Service provides a highly scalable, self-patching web hosting service. This quickstart shows how to deploy a PHP app to Azure App Service on Linux. You can follow the steps here using a Mac, Windows, or Linux machine. Once the prerequisites are installed, it takes about five minutes to complete the steps.

Can HTML be deployed with Azure?

Azure App Service is the fastest way to deploy an HTML/CSS/Javascript application in minutes on Azure. All you need is an Azure account and repo.

Where is config JSON Staticwebapp?

The recommended location for the staticwebapp. config. json is in the folder set as the app_location in the workflow file. However, the file may be placed in any subfolder within the folder set as the app_location .

Can Microsoft Azure host a website?

Azure App Service enables you to build and host web applications in the programming language of your choice without managing infrastructure. Learn how to create a website through the hosted web app platform in Azure App Service.


1 Answers

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:

http://blog.dezfowler.com/2010/09/aspnet-custom-error-not-shown-in-azure.html

like image 51
nklhead Avatar answered Sep 28 '22 18:09

nklhead