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.
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.
<configuration><location path="default.aspx"><system.webServer><httpRedirect enabled="true" destination="pages/default.aspx" exactDestination="true" httpResponseStatus="Found" /></system.webServer></location></configuration>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:
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.
<configuration><location path="default.aspx"><system.webServer><httpRedirect enabled="true" destination="pages/default.aspx" exactDestination="true" httpResponseStatus="Found" /></system.webServer></location></configuration>