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

2019-01-26 00:50发布

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.

3条回答
爷的心禁止访问
2楼-- · 2019-01-26 01:16

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.

查看更多
唯我独甜
3楼-- · 2019-01-26 01:16

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.

查看更多
祖国的老花朵
4楼-- · 2019-01-26 01:38

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)!

查看更多
登录 后发表回答