[ACCEPTED]-asp.net site default document in subfolder-iis-7

Accepted answer
Score: 17

Default document is not the same as start 10 page. Default document means if I requested 9 mysite.com/somefolder and didn't specify a file, which file should 8 IIS display.

If you want to use a specific 7 page as your home page, create a Default.aspx 6 file and write this in it's codebehind class:

public override void ProcessRequest(HttpContext context) {
    context.Response.Redirect("pages/default.aspx", true);

As 5 the client might have disabled Javascript, a 4 server side approach would be more reliable. However 3 it's best to issue a permanent redirect 2 instead of a simple Response.Redirect. Also doing it using 1 JS will be bad from a SEO point of view.

Score: 9

You don't need to create a dummy Default.aspx 2 page.

In your Global.asax.cs file, write 1 the following:

public void Application_Start(object sender, EventArgs e)
    var routeCollection = RouteTable.Routes;
    routeCollection.MapPageRoute("DefaultRoute", string.Empty, "~/YourDesiredSubFolder/YourDesiredDocument.aspx");


  • Application_Start code is guaranteed to run once and only once on the application start.
  • The first line of code, gets a collection of the URL routes for your application.
  • The second line of code, defines a new route pointing to your inner page in the subfolder that you wish.
  • The second argument is empty to indicate that this route is used when there's no specific page is requested and there's no Default document existing.
Score: 2

Default documents are a subfolder-specific 6 thing - what you're trying to do won't (directly) work. Set 5 up a default.htm file in the root, and have 4 it refresh to your real "home page".

The 3 better question you should be asking is 2 how on Earth your homepage got out of the 1 root directory.

Score: 0

In theory you could have a Web.config file 5 inside the directory and use the defaultDocument element to set 4 the default document. See here: https://stackoverflow.com/a/2012079/125938.
Unfortunately 3 I haven't been able to get it to work myself 2 locally, but that might be because it isn't supported 1 in the Visual Studio development server.

Score: 0

Say "index.html" is the default page you 3 want and it is present in "Public" subfolder.

Instead 2 of specifying "/Public/index.html" as the 1 default site, try "Public/index.html"

More Related questions