Different Default Document for IIS Sub Application - asp.net

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>

Related

Forward domain alias to a certain page

We have a domain (domain.com) that has an alias (alias.com). We are using Plesk and a Windows Server. In Plesk, alias.com is setup as an alias for domain.com.
We need that when people access to alias.com it goes to a certain page within the main domain, for example domain.com/this-page.html.
The web site is an ASP.NET MVC web site, in case we can do something using the web.config.
Is this possible? How can we do this?
Open web.config in the directory where the old pages reside
Then add code for the old location path and new destination as follows:
<configuration>
<location path="services.htm">
<system.webServer>
<httpRedirect enabled="true" destination="http://example.com/services" httpResponseStatus="Permanent" />
</system.webServer>
</location>
<location path="products.htm">
<system.webServer>
<httpRedirect enabled="true" destination="http://example.com/products" httpResponseStatus="Permanent" />
</system.webServer>
</location>
</configuration>

Set Default Start Document

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

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>

Problem when default page is MainPage.aspx not Default.aspx

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.

Resources