I expected this would also map the default homepage as in http://localhost/ but it is not hit.
RouteTable.Routes.Add(new Route("{Keyword}", new HomeHandler()));
Question is of course why not? I would like to map the root to some other page.
I haven't tried this yet but try removing the default document from IIS's configuration. For IIS 7 this setting is in web.config:
<configuration>
<system.webServer>
<defaultDocument>
<files>
<clear />
</files>
</defaultDocument>
</system.webServer>
</configuration>
The answer is somewhat complex. It was on IIS6 and we had to add a specific property. I cannot really remember what we did back then but you can google it, that's how I found it.
Related
I have a website developed in ASP.NET. I have it hosted in IIS and say the url is www.web.com. Whenever I request for this page by typing the URL in the browser I am redirected to the login page with URL like this www.web.com/Login.aspx?ReturnUrl=%2f.
I have added the following in web.config so as to make Default.aspx as my Default page.
<defaultDocument>
<files>
<clear/>
<add value="Default.aspx"/>
</files>
</defaultDocument>
Also,
<forms loginUrl="Login.aspx" defaultUrl="~/Default.aspx">
The pages are present on root folder, so I tried few things already mentioned here. Is there anything else I am missing ? A direction towards a solution or any links would be helpful.
Edit: The website redirects to Default.aspx when run on localhost
A couple of minor differences, but may help. I also assume you are using IIS 7 or higher.
If they are at the same folder level, you can try:
<forms loginUrl="Logon.aspx" defaultUrl="Default.aspx"/>
You can try:
<defaultDocument enabled="true">
<files>
<clear/>
<add value="Default.aspx"/>
</files>
</defaultDocument>
I have a website with the default settings for default document on IIS 8.5 Windows 2012 R2.
<system.webServer>
<defaultDocument enabled="true">
<files>
<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>
</system.webServer>
When I browse to a URL without a file name (mysite.com/Content/) IIS will only try default.aspx and no other files in the list (index.html). IIS tries to load default.aspx and I get a 404. The strange thing is there is no default.aspx file in that directory and index.html does exist. If I browse directly to index.html the page displays properly. According to the Microsoft documentation on default document it should try the next file in the list until it finds one that exists.
I explicitly added a web.config file to the sub directory with
<defaultDocument enabled="true">
<files>
<clear />
<add value="index.html" />
</files>
</defaultDocument>
and IIS is still trying to use default.aspx. Has anyone encountered this before? Do you have any suggestions as to why this is not working as documented?
Try removing/disabling the old URL rewrite module? (temporarily)
If you are requiring authentication, make sure the login page exists.
(other suggestions copied from above, which I have included, in case someone
else reads this question)
Check for any routing in the source-code.
Check any special modules or handlers, which might cause redirects or intercept calls.
One method for making default document directive to work is:
Go to IIS/Application Pools
Change the ‘Managed Pipeline Mode’ to Classic mode instead of Integrated Mode.
This worked for me.
If you disable default documents but have enabled directory browsing, IIS returns a directory listing when a request for the root directory arrives from a browser. If you disable both default documents and directory browsing, IIS sends an "HTTP 404 File Does Not Exist" error to the browser.
So please enable default documents option in IIS and reset IIS.
If you want use index.html as a default page. you need to click on iis default website after that you can click on default document. Now! you can add index as default page.
This seems pretty simple, but for the life of me I can't figure it out.
Using ASP.NET Classic (ie non-MVC), say I have a website www.foo.com that has an /api folder, and in that folder is the file api.aspx (i.e. you hit www.foo.com/api/api.aspx)
How can I set things up (either via Web.config rewrite or via MapPageRoute() in Global.asax.cs) so that www.foo.com/api
hits /api/api.aspx not /api/Default.aspx
doesn't show api.aspx in the browser's URL box (I just want to see either www.foo.com/api or www.foo.com/api/)
I would have thought that this would work:
routes.MapPageRoute("ApiRoute","api","~/Api/Api.aspx");
but it doesn't... I still hit /api/Default.aspx
EDIT:
I also want to support /abc/abc.aspx and /thing/thing.aspx, mostly so when I have these pages open in the IDE they're not all named "Default.aspx" and I can't quickly see which page is which.
I've created a small demo project. Each folder I want to set a specific default document I add a web.config file.
project structure
Each web.config file defines a default file for it's folder.
web.config in folderA
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<defaultDocument enabled="true">
<files>
<clear/>
<add value="a.aspx"/>
</files>
</defaultDocument>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Accordingly for folderB
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<defaultDocument enabled="true">
<files>
<clear/>
<add value="b.aspx"/>
</files>
</defaultDocument>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
ATTENTION
When I did some tests in my development webServer it did not work. But
when I published my project to my local IIS instance it did work out
all right.
local IIS deployment
We have a few sites that are all controlled via one CMS, even though they have their own domain name. They are all hosted under the one account.
I want to set the default page to index.html on one of the domains via web.config
So for example, with abc.com i want it to default to abc.com/index.html but leaving the other domains as they are.
While I can set the default to index.html it seems to break the other sites, as they redirect back to this on every occasion.
Try to wrap redirect rule with location element and specify your domain in the path attribute.
UPDATE
I think it should be something like this:
<configuration>
...
<location path="http://abc.com">
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="index.htm" />
</files>
</defaultDocument>
</system.webServer>
</location>
...
</configuration>
I have very strange problem. I'm using IIS 7.0 Integrated mode for my application. (pool is ASP 2.0 integrated)
It's working fine when i type www.xyz.com/MainPage.aspx. But when i used simple www.xyz.com then its not working.
I always get this error
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /intranet/default.aspx
I have mapped default document to MainPage.aspx still its not working... I don't have default.aspx page in root. only Mainpage.aspx and I can't change it...
my web.config looks like this (only part of it :):
<configuration>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="MainPage.aspx" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
Check you web.config and make sure the default.aspx is not listed as one the default pages. Recycle the app pool and restart IIS.
<system.webServer>
<defaultDocument>
<files>
<remove value="Default.htm"/>
<remove value="Default.asp"/>
<remove value="index.htm"/>
<remove value="index.html"/>
<remove value="default.aspx"/>
<remove value="iisstart.htm"/>
<add value="MainPage.aspx"/>
</files>
</defaultDocument>
You need to add MainPage.aspx as default page through IIS's document facility. You may also add a default document with IIS7 web.config.
<configuration>
<system.webServer>
<defaultDocument>
<files>
<add value="MainPage.aspx" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
I think this setting is locked in IIS7 on applicationHost.config level. You have to change the root config gile or use IIS Administration API do complete this task.