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

2019-06-25 21:01发布

当我构建和运行我的应用程序,我得到一个目录列表在浏览器( 也恰好为子文件夹 ),我有点击的Index.aspx。 它让我疯了。

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

Answer 1:

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

该项目必须有ATLEAST一个空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();
    }
}


Answer 2:

右键单击想要作为默认页中使用,并选择“设置为起始页”只要您运行从Visual Studio的Web应用程序的网页上,它会打开选​​定的页面。



Answer 3:

转到项目的属性页中,选择“网络”选项卡,并在顶部(在“开始行动”一节),在“特定页”框中输入页面名称。 你的情况的Index.aspx



Answer 4:

类似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");
        }
    }
}


Answer 5:

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


Answer 6:

如果要针对IIS,而不是VS Webdev的服务器上运行,确保Index.aspx的是默认的文件之一,目录浏览被关闭。



Answer 7:

这一个方法发布的解决方案在启动时显示特定页面。

这里是路由实例重定向到特定页...

public class RouteConfig
{
    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 },
            namespaces: new[] { "YourSolutionName.Controllers" }
        );
    }
}

默认情况下,家庭控制器指数方法执行应用程序启动时,在这里你可以定义你的。

注:我使用Visual Studio 2013和“YourSolutionName”就是改变你的项目名称..



文章来源: Setting the default page for ASP.NET (Visual Studio) server configuration