Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net site default document in subfolder

Tags:

asp.net

iis-7

My default document is in subfolder not in root how can i make it default in asp.net 2.0 website.

Tried iis7 default document setting to '/pages/default.aspx' '~/pages/default.aspx' but it didn't work.

like image 673
mamu Avatar asked Jan 07 '09 19:01

mamu


2 Answers

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

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

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

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

like image 173
mmx Avatar answered Sep 21 '22 08:09

mmx


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

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

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

Explanation:

  • 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.
like image 43
Mohamed Emad Avatar answered Sep 25 '22 08:09

Mohamed Emad