IIS: Default Document without web.config

campinam
campinam used Ask the Experts™
on
Can one set the default page of a web site or application  without changing the web.config file for that site or application?

(Using Windows Server 2019)
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Distinguished Expert 2017

Commented:
Not sure I understand what you are after.

When you Define the root for a site, the web.config is created with base rules.

When you change, the web.config in the original location is no longer applicable.
Sam JacobsDirector of Technology Development, IPM

Commented:
If you back up default.htm in the web root (usually c:\inetpub\wwroot), and replace with the following, it should redirect users:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>Redirecting ...</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="ROBOTS" content="NOINDEX, NOFOLLOW, NOARCHIVE">
        <script type="text/javascript">
            <!--
            function redirectToWebsite() {
                    location="/defaultSite/";
            }
            -->
        </script>
    </head>
    <body onLoad='redirectToWebsite();'>
    </body>
</html>

Open in new window

Author

Commented:
I meant defining the default document, and one does that when configuring the site in IIS. What one does in IIS Manager is reorder the pages in the default document list, or delete some there, or add new. But such operations automatically change the web.config file for the site. My question was, can one define the default page without altering web.config?
11/26 Forrester Webinar: Savings for Enterprise

How can your organization benefit from savings just by replacing your legacy backup solutions with Acronis' #CyberProtection? Join Forrester's Joe Branca and Ryan Davis from Acronis live as they explain how you can too.

Sam JacobsDirector of Technology Development, IPM

Commented:
Sorry … I misunderstood.
I'm afraid that altering the default page on a website is reflected in the web.config file.
Charlie ArehartTroubleshooting Consultant

Commented:
@campinam: Yes, you should be able to change the location ("default directory") of a web site, without that change altering the web.config.

The site's directory location is stored (by default) not in the web.config but instead in the applicationhost.config (in windows/system32/inetsrv/config).

The question is a bit curious because you should be able to see readily whether the site's location/default directory Is stored in the web.config or not. Is it for you?

To be clear, it IS possoble to define SOME config settings in EITHER file (while some settings can only be set In applicationhost.config, unless an override is specifically permitted in that app host file).

If somehow you DO find that the site's location IS defined in the web.config, you certainly CAN define it in the app host file instead. If you look there or in the docs, you can see how  and where that's done.

Indeed, if you create a new site you will see its location defined in that app host file and can then use that as a model for moving your location out of the web.config and. Into there, if indeed that's your issue here.

Let us know if I'm guiding you down the right path.

Author

Commented:
My apologies, I meant "default document" all the time,  not "default directory". I corrected the question and my comment. So sorry about that. That's what I was hoping I can change without altering web.config (because actually there are other site settings that are not recorded in web.config)
Troubleshooting Consultant
Commented:
Ah, ok. Well yes, again you can (generally) configure things EITHER in  the web.config OR in the applicationhost.config. In the latter, there is a place in the file where iis CAN put site-specific settings.

And you can cause that placement of those settings either by hand (moving them out of the web.config), or when configuring things with appcmd or powershell, or even with a rather hidden feature in the IIS ui.

But you've asked if the default document config for a site CAN be done without modifying the web.config. So the answer is still yes.

Your next question may be, "ok, but if I do move the default doc settings for a site to the applicationhost.config, and then I or someone modifies that with the IIS ui, will THAT change be written to the web.config?"

I do believe the answer is no, but I'm not at a computer to test. Can you or anyone else confirm, if indeed that is your next question?

Author

Commented:
I can confirm that changes to default doc in IIS Manager translate automatically into changes to web.config. I wonder, is there a setting in the IIS Manager UI that can stop that... and record the default doc somewhere else. What is that hidden feature in IIS Manager, you mentioned?
Distinguished Expert 2017

Commented:
Pkease clarify what you are looking for and why it is you are trying to prevent updates to web.config?

Within iis management you can define a list of and in a specific order that iis will look for
This entry is added into web.config
Web.config is the information iis relies on for handling requests.

Author

Commented:
I'd like web.config to be free of IIS interference because it can be edited in Visual Studio or other page editors and careless publishing of site or application by some developer can overwrite it.
Sam JacobsDirector of Technology Development, IPM

Commented:
I haven't tried this, but according to Microsoft documentation, you may be able to prevent certain updates to web.config by locking the configuration. See: Getting Started with IIS Manager
Distinguished Expert 2017

Commented:
different apps add/change different sections of the config.
Have seen issues as you mention where the server has one version of .net, while a development platform has multiple, and when published the wrong .net version is pushed out...
Distinguished Expert 2017

Commented:
I do not believe in the course of publishing from visual studio, while web.config is updated, the iis settings within are not altered.

The issue you might be dealing with relates to a different way the site is published presumably through which the local web.config on the development side is copied into it.

Author

Commented:
Right, that happened (copy of an app's files manually), and I just wanted a single source of editing web.config, Visual Studio, and not any altering on the server.
Distinguished Expert 2017

Commented:
Do you share the web folder? Or use FTP to update versus using WebDAV?
Cte's apps are published into their own directories versus into the top.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial