asp.net site default document in subfolder

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.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.

Method 2

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.

Method 3

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

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

Method 4

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

Method 5

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

Instead of specifying “/Public/index.html” as the default site, try “Public/index.html”


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x