Set default webpage for website on Microsoft Windows Azure

梦想的初衷 提交于 2019-11-29 10:45:13

According to this blog post: http://blogs.msdn.com/b/cesardelatorre/archive/2010/07/22/how-to-set-a-default-page-to-a-windows-azure-web-role-app-silverlight-asp-net-etc.aspx

<defaultDocument> 
          <files>                           
             <clear/>                           
             <add value="Default.aspx"/>                      
          </files>
</defaultDocument>

Should Work. Or you could Type to Url map it. To do that check out http://msdn.microsoft.com/en-us/library/cc668201.aspx

If you are using MVC or Web API, add the following line in RegisterRoutes():

   routes.IgnoreRoute(""); 

This solved my problem. Hope it helps you.

If you app is a MVC application, it looks for the default controller instead of default pages.

So you must map a route in RouteConfig. In my case,I wanted to load the site with an index.html page, so I did:

RouteConfig.cs file:

 public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id =    UrlParameter.Optional }
        );
    }

And in my HomeController, Index Action, write this code:

public ActionResult Index()
    {
        return Redirect("/index.html");
    }

This works fine in Azure with a Shared Site. I hope this will help you.

Do you have a typo?

You have:

<add value="Default.aspx" />

But you said that your "home page" that works is /home.aspx.

If you want for /home.aspx to be displayed when the user goes to http:/website.azurewebsites.net/, then I can think of several ways for you to accomplish that.

Since you have Default.aspx as your defaultDocument, you can rename home.aspx to Default.aspx and when someone goes to http:/website.azurewebsites.net/ the contents of Default.aspx will be displayed.

If you need to keep home.aspx named as home.aspx for some reason, then as you requested if you want for http:/website.azurewebsites.net/ to redirect to /home.aspx then create a file called Default.aspx in the root directory and edit it to contain Response.Redirect("home.aspx", false);. A complete example for this type of page is available at http://msdn.microsoft.com/en-us/library/a8wa7sdt(v=vs.80).aspx.

Update:

Try adding enabled="true" to your defaultDocument XML tag. See the example below from http://www.iis.net/ConfigReference/system.webServer/defaultDocument

 <system.webServer>
      <defaultDocument enabled="true">
         <files>
            <add value="home.html" />
         </files>
      </defaultDocument>
  </system.webServer>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!