Default Document not trying all files in IIS 8.5 - asp.net

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.

Related

How to register an IHttpHandler as a default document

I have an IHttpHandler registered in web.config like so:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<!-- These are the HTTP handler registrations for IIS7+ in Integrated Pipeline mode; that is the current recommended mode for all deployments. -->
<handlers>
<add name="LaunchHandler" verb="GET,POST" path="launch.axd" preCondition="integratedMode" type="Foo.LaunchRequestHandler, Foo" />
...
</handlers>
</system.webServer>
This works fine if I navigate to /launch.axd directly, but I want this handler to run for the root path.
My initial approach was to create a default.aspx page that redirects to launch.axd, this does work but obviously requires an extra roundtrip to the browser.
As an alternative to using a default.aspx page I tried adding launch.axd as a Default Document, like so:
<defaultDocument>
<files>
<add value="launch.axd"/>
...
</files>
</defaultDocument>
However this does not work. Navigating to to root path returns this message:
HTTP Error 403.14 - Forbidden
The Web server is configured to not list the contents of this directory.
Most likely causes:
A default document is not configured for the requested URL, and directory browsing is not enabled on the server.
I.e. the request is being handled by DirectoryListingModule.
Any ideas? Can a handler that is not backed by a file (aspx, ashx) be registered as a default document?

Trying to secure all aspx files in a folder secure by IP address

I like to secure all aspx files in a folder ~/Secure/ secure such that specific IP addresses can access the folder's aspx files. I added the following web.config file to the folder, hoping that it adds to the parent web.config:
<configuration>
<system.webServer>
<security>
<ipSecurity allowUnlisted="false">
<clear/>
<add ipAddress="192.168.100.1" />
<add ipAddress="169.254.0.0" subnetMask="255.255.0.0" />
</ipSecurity>
</security>
</system.webServer>
</configuration>
The problem is that I get this error when I try to access to any of the aspx pages in the folder:
This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".
What does it take to make this idea happen? I like to just include one web.config file to a folder and that enforces the IP address authorization. I like this idea, since it is no-code and config only.
You cannot do it in the website web.config only.
If you can use IIS manager:
Open IIS Manager, locate the site, click on the folder you want to protect, then click on IP address and Domain Restrinctions.
Also click on "Edit feature settings" in the right Actions panel" to specify actions for unspecified clients (i.e. Deny with Forbidden, or simply Deny With Not Found).
This will generate the right configuration for you.
In your root web.config use the location element:-
<location path="Secure">
<system.webServer>
<security>
<ipSecurity allowUnlisted="false">
<clear/>
<add ipAddress="192.168.100.1" />
<add ipAddress="169.254.0.0" subnetMask="255.255.0.0" />
</ipSecurity>
</security>
</system.webServer>
</location>

Windows ASP.NET redirection

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>

Why I'm getting "HTTP Error 403.14 - Forbidden" error after redirecting URL?

This is my solution structure.
When users hit in this http://localhost/RouteUrl/ URL I want to redirect them to http://localhost/RouteUrl/UI/MainForm.aspx.
In web.config file within system.web section I've written:
<urlMappings enabled="true">
<add url="~/RouteUrl" mappedUrl="~/UI/MainForm.aspx" />
</urlMappings>
And when I browse http://localhost/RouteUrl/ it shows HTTP Error 403.14 - Forbidden. The Web server is configured to not list the contents of this directory
When I directly browse http://localhost/RouteUrl/UI/MainForm.aspx it simply shows the page, doesn't show any error.
I don't want to enable directory browsing. What I'm missing? How I should properly redirect the URL?
Finally I find out the problem. The ~ itself points to the root directory and in <add /> tag I've written url="~/RouteUrl".
So the corrected <add /> tag will be:
<add url="~/" mappedUrl="~/UI/MainForm.aspx" />
I believe your issue is with the trailing /. Your route is to ~/RouteUrl and you are entering ~/RouteUrl/, which would act as the root of a directory and with directory browsing is turned off, you receive a 403 error.
Adding <modules runAllManagedModulesForAllRequests="true" />
to the <system.webServer> section in the web.config works for me.

Different Default Document for IIS Sub Application

I have an IIS website running an ASP.NET site but it has multiple applications running under it (a virtual directory with separate app pools basically).
Well - I need two separate applications which point to the same root folder director but I want the apps to have separate default documents. The reason is because this is how it is configured in production and this is on my development box.
The problem is that IIS keeps giving me the SAME default document for both apps (which are separate virtual paths and separate app pools just same physical location). How can I overcome this or can I not in IIS7?
I am going to be re-writing the whole thing and it will not be done this way in the furture...but until then I need to fix some bugs and want a local dev environment. Help!
In order to accomplish this and preserve the setup implemented in our sites I needed to add a location tag around the System.WebServer element in the root site web.config and specify the default document in there as follows where the path is the VirtualDirectory/Application name:
<location path="VirtualDirectoryName">
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="Document.asp" />
</files>
</defaultDocument>
</system.webServer>
</location>
<location path="VirtualDirectoryName2">
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="AnotherDocument.asp" />
</files>
</defaultDocument>
</system.webServer>
</location>

Resources