设置ASP.NET(Visual Studio)服务器配置的默认页面

Dan*_*ams 27 asp.net configuration visual-studio-2008

当我构建并运行我的应用程序时,我在浏览器中获得了一个目录列表(对于子文件夹也是如此),我必须单击Index.aspx.这让我发疯了.

Visual Studio 2008 ASP.NET开发服务器9.0.0.0

Jam*_*aro 39

右键单击要用作默认页面的网页,并在从Visual Studio运行Web应用程序时选择"设置为起始页",它将打开所选页面.

  • 是的,适用于起始页面,但当我浏览到子文件夹中的任何内容时,我再次获得一个文件夹列表. (7认同)

zpr*_*oxy 20

内置的Web服务器硬连线使用Default.aspx作为默认页面.

该项目必须至少有一个空Default.aspx文件来克服目录列表问题Global.asax.

:)

添加该空文件后,可以在一个位置处理所有请求.

public class Global : System.Web.HttpApplication
{
    protected void Application_BeginRequest(object sender, EventArgs e)
    {
        this.Response.Write("hi@ " + this.Request.Path + "?" + this.Request.QueryString);
        this.Response.StatusCode = 200;
        this.Response.ContentType = "text/plain";

        this.Response.End();
    }
}
Run Code Online (Sandbox Code Playgroud)


Phi*_*ert 11

转到项目的属性页面,选择"Web"选项卡并在顶部(在"开始操作"部分中),在"特定页面"框中输入页面名称.在您的情况下index.aspx

  • 是的,适用于起始页面,但当我浏览到子文件夹中的任何内容时,我再次获得一个文件夹列表. (3认同)
  • 内置的Web服务器硬连线使用Default.aspx作为默认页面.也许您的团队成员使用Default.aspx而不是index.aspx?或许他们在他们的机器上使用本地IIS进行开发. (2认同)

Jon*_*ams 8

类似于上面的zproxy的回答,我使用了Gloabal.asax.cs中的下面的代码来实现这个目的:

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");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)