Setting the default page for ASP.NET (Visual Studio) server configuration

前端 未结 8 753
北荒
北荒 2020-12-05 13:38

When I build and run my application I get a directory listing in the browser (also happens for sub folders), and I have to click on Index.aspx. It\'s makin

8条回答
  •  有刺的猬
    2020-12-05 14:19

    Similar to zproxy's answer above I have used the folowing code in the Gloabal.asax.cs to achieve this:

    public class Global : System.Web.HttpApplication
    {
        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            if (Request.Url.AbsolutePath.EndsWith("/"))
            {
                Server.Transfer(Request.Url.AbsolutePath + "index.aspx");
            }
        }
    }
    

提交回复
热议问题