1

Using IIS 7 how do I configure a website to be available at a specific url?

If I create a directory with an index.html file in, and create a website using that directory, the website's url is 'http://localhost', how do I get it to be served at 'http://localhost/Application1' instead?

I've spent an hour scouring the web looking for solutions for what appears to be the most obvious configuration imaginable. I've seen two possible approaches.

  1. Create a virtual directory with the desired url that is configured to address a physical directory that serves no purpose and then create the applciation as a child of that directory. Tried it, IIS just complained that the location couldn't be found.

  2. Install some sort of url rewriting module and then decide whether I want to spend the next hour or so working out how to configure it or just kill myself instead.

There must be a more straightforward solution surely??

UPDATE

I've noticed something else that doesn't make any sense. If I create a new website inetpub/wwwroot2 and under that create two applications App1 and App2, (each directory containng a simple static index.html). In IIS Manager if I attempt to create a virtual directory using App1 or App2 and click 'Test Settings' there is an Authorization error that states:

"The server is configured to use pass-through authentication with a built-in account to access the specified physical path. However, IIS Manager cannot verify whether the built-in account has access. Make sure that the application pool identity has Read access to the physical path. If this server is joined to a domain, and the application pool identity is NetworkService or LocalSystem, verify that \$ has Read access to the physical path. Then test these settings again."

After more rummaging around on the web I discovered a solution for this, which I'll post as a possible answer.

Neutrino
  • 8,496
  • 4
  • 57
  • 83

3 Answers3

2

IIS can often be confusing and frustrating, even if you know how the underlying protocols and systems work. First, you can't have a web site on the internet at a particular path. The host name (and/or IP address and port) determines the server that controls the site. Paths are simply a convenient organizational tool within a site. Given this restriction, IIS naturally requires that you create something that listens at the hostname (again, and/or IP address and port) level. IIS calls this a "site". Once you've created your site, you can create an application or virtual directory within that site. The only difference between an application and a virtual directory is that an application can run its own code in its own application pool. Either one always handles a subpath of its parent (which is either the site or another virtual directory or application). This is because of how IIS processes the request. After finding the appropriate application for the request by using the IP address, port, and hostname, it sends the request to the application. The application then looks at the first part of the path given in the request and uses that to find the appropriate application or virtual directory, which then does the same thing with the next part of the path until it cannot match the next subpath part to a configured application or virtual directory. If the last item found is a virtual directory, it just serves up the static files at the configured physical path. If it's an application, it passes control to the code for the application if there is any. If there is no code for the application, it treats the application as if it were just a virtual directory.

When you're setting up your own website, you can either use the preconfigured 'Default Web Site', which listens to port 80 on all IP addresses, or a site you create yourself. However, keep in mind that IIS can easily get confused if you try to create two items that listen to the same URL, so if you create your own site that attempts to listen to the same URL as the default web site, it won't work. You may need to disable (or delete) the default web site first, by right-clicking on the site and choosing Manage Web Site/Stop.

Application Pools can be thought of as crash protection boundaries. Applications in one pool are protected from crashes in other pools. By default, an application pool is created for each new site, and is named the same as the site (so each site is protected from other sites). You can override the default application pool mapping during site creation or afterwards.

When troubleshooting or first setting up a system, it's usually a good idea to first get the site working (and make sure you're hitting the site you think you're hitting), then add the applications one at a time and get each of those working (without messing with the site). If you have code at any of the levels, first test it without the code and then test it with the code. If the static files succeed but the code doesn't, it may be an application pool settings issue. Test it from the local machine first, then from another machine (if needed). If it works locally, but not from another machine, it's probably a firewall or network issue.

See also: https://webmasters.stackexchange.com/questions/72488/does-iis-7-5-use-a-separate-appdomain-for-each-subdomain/72650#72650

James
  • 3,551
  • 1
  • 28
  • 38
  • Reading through what you have written it seems that if I have an IIS application at 'WebSite1/Application1' that I need something to exist at 'WebSite1' that fowards all './Application1' urls to Application1. Is there nothing straightforward that can do this? If not how is IIS supposed to serve more than one website, or is it only intended to serve one website? – Neutrino May 30 '17 at 15:44
  • According to this https://stackoverflow.com/a/6297660/954927 I should be able to add multiple sites under inetpub/wwwroot and access them as localhost/website1 localhost/website2 etc. But when I set up IIS in this way with a simple static file at wwwroot/website1 and wwwroot/website2 and navigate to localhost/website1 I get an error which indicates the request is being routed to inetpub\wwwroot\index.html which cannot be found. – Neutrino May 30 '17 at 16:06
  • On a given server, you can set up as many sites as you like. In a given site, you can set up as many applications as you like, and on a given application, you can set up as many virtual directories as you like. – James May 30 '17 at 19:38
  • Where are the files you're trying to serve up and how did you configure IIS to point to that directory? – James May 30 '17 at 19:39
  • The site can be completely empty (in this case, it just acts as a holder for applications). The same also holds true for applications (in which case they're basically just a virtual directory). – James May 30 '17 at 19:40
  • I have inetpub/wwwroot/website1 which contains Application1 and Application2. All directories contain a simple helloworld index.html. I added Website1 to IIS as a website. Then in IIS I opened the WebSite1 node and it shows the raw directories Application1 and Application2. I right clicked on each of them and selected 'convert to application' and restarted WebSite1. Navigating to localhost/website1/application1 shows the index.html for website1 instead of the index.html for application1. I can't access the index.html for application1 or application2 no matter what I do. – Neutrino May 31 '17 at 09:18
  • If I remove the index.html file from WebSite1 and restart then navigating to localhost/website1/application1 gives an error stating website1/index.html cannot be found. – Neutrino May 31 '17 at 09:19
  • The application pool stuff is a bit confusing. When creating WebSite1 you have to enter a 'site name'. Whatever you enter as the site name overwrites the original Application Pool. I've tried this both using the new WebSite1 application pool that gets entered when you enter the site name, and setting it back to DefaultAppPool with the same result in all cases. – Neutrino May 31 '17 at 09:22
  • See 3 new paragraphs in answer – James May 31 '17 at 12:45
1

There is an elegant solution to this problem using default page.

First create "Default.aspx" file with content similar to this:

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <%
            //redirect to specific web application. You can also parse request and redirect to specific application...
            Response.Redirect(@"http://www.example.net/Application1");          
        %>
    </div>
    </form>
</body>
</html>

Copy this file on IIS root (commonly "C:\inetpub\wwwroot") and add default document on Default Web Site "Default.aspx" if already not exists.

So how this works? When request comes to IIS root, IIS will look for default document. In this case will be "Default.aspx". This page will then redirect client to your target application.

Of course you can use the same principle with plain HTML document on IIS root.

Gregor Primar
  • 6,759
  • 2
  • 33
  • 46
1

I discovered a solution to the authentication issue of the default IIS configuration not being able to access the content directories you create here https://forums.iis.net/search?q=authors%3A%28Beaker007%29&s=postDate&d=desc

  1. Start > Administrative tools > Internet Information services(IIS) Manager
  2. Server name > sites ,then right click the "Default Web Site" > "Add virtual directory" and fill in the name and the path to the directory to be shared
  3. After the virtual directory appears under the Default web site three , rigth click on it > edit permissions > Security > edit
  4. Add: the local IUSR , ANONYMOUS LOGON and NETWORK SERVICE they need at least "Read" and "List folder contents" rigths
  5. Switch to feature view , in the central pane double click "directory browsing" and click "enable" under the action pane on the right ( Be sure your newly created virtual directory is highligthed )
  6. In Features View, double-click Authentication > On the Authentication page, select Anonymous Authentication.
  7. In the Actions pane, click Edit to set the security principal under which anonymous users will connect to the site.
  8. In the Edit Anonymous Authentication Credentials dialog box, select one of the following options: -- Specific user, ( IUSR ) -- Application pool identity, if you want IIS processes to run by using the account that is currently specified on the property page for the application pool. By default, this is the Network Service account. Important If you use the Network Service account, you grant anonymous users all the internal network access associated with that account.

After using this process to add virtual directries to my IIS website tree I was able to convert the virtual directories to applications with no problem.

Neutrino
  • 8,496
  • 4
  • 57
  • 83
  • Dude, I feel your pain. IIS is so un-intuitive. I have this exact same problem. Thank you for the writeup – Iofacture Mar 09 '19 at 01:04