Change Default “Default.aspx” to “Index.aspx” on V

2019-01-26 00:52发布

问题:

Whenever I create a new Web Form on Visual Studio 2010, the default name is always "Default.aspx". This is a slight pain as I'm having to change it to "Index.aspx" each time.

How can I change this so that "Index.aspx" is the default name?

Thanks.

回答1:

You can by modifying the associated .vstemplate DefaultName element. For example, you might find the webform template you need to modify in a directory similar to the following: C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Web\1033. Each template file is managed within a zip file like WebForm.zip. Unzip the contents, modify the .vstemplate DefaultName element and reapply the changes to the same templates folder. Your updates should be reflected in Visual Studio. (You might need to restart VS.)

As an alternative, you should consider creating your own template (based off the original) instead of modifying the default template.



回答2:

No, there is no way do to that in Visual Studio. You can only do that in IIS.

But, you can define a Startpage in the Property-Pages (Web) of the ASP.NET Webpplication.



回答3:

Although this does not cover all scenarios 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");
        }
    }
}

*You must remember to remove this code when deploying the code (or wrap in DEBUG statements)!