Tarik Tarik - 4 months ago 29
ASP.NET (C#) Question

Set Default Page in Asp.net

Is there any section or code which allows us to set default page in

web.config
?

For example, when people first visit my website, I want them to see
CreateThing.aspx
rather than
Default.aspx
.

The solutions I know :


  1. Put this line of code =>
    Response.Redirect("CreateThings.aspx")
    in
    Default.aspx
    Page_Load
    event but this method is really naive.

  2. We can use
    IIS
    (default page configuration) but I wanna do the same thing over Asp.NET application.



If you know a better solution, please let me know.

Thanks in advance.

P.S : The reason why I am asking about
Web.Config
is I believe
Web.Config
would help us through this.


Edit:
I am just wondering how Microsoft .NET team forgot such a simple thing :)

Edit :

This could be another solution for now :

<defaultDocument>
<files>
<clear />
<add value="Default.aspx" />
<add value="Default.htm" />
<add value="Default.asp" />
<add value="index.htm" />
<add value="index.html" />
<add value="iisstart.htm" />
</files>
</defaultDocument>

Answer

If using IIS 7 or IIS 7.5 you can use

<system.webServer>
  <defaultDocument>
    <files>
      <clear />
      <add value="CreateThing.aspx" />
    </files>
  </defaultDocument>
</system.webServer>

http://www.iis.net/ConfigReference/system.webServer/defaultDocument