Unique identifier for web apps on iis - iis

When I add a new web application in IIS, is there any unique identifier created for that application? And by unique I mean that if the application is deleted and a new one is added, the new one won't take the old app's ID.

Starting from IIS7 a Website or WebApplication is configured inside the applicationHost.config file located in the `C:\Window\System32\inetsrv\config\ directory.
If you browse the <site> section configuration here : http://www.iis.net/configreference/system.applicationhost/sites/site you can see that there is only one id which is unique in IIS but no globally unique.
Unfortunately there is no unique identifier for the website.

Related

Inherited web.configs with ASP.NET Core Equivalent

My company is exploring ASP.NET Core. We currently use ASP.NET Web API 2 & MVC 5.2.2. We deploy our applications under IIS using the following configuration:
VirtualDirectory1 (web.config with connection string and other non-specific information)
App1 (app specific web.config)
App2 (app specific web.config)
Api1 (api specific web.config)
Api2 (api specific web.config)
VirtualDirectory2 (web.config with connection string and other non-specific information)
App1 (app specific web.config)
App2 (app specific web.config)
Api1 (api specific web.config)
Api2 (api specific web.config)
As you know, each application or API inherits configuration from the parent web.config under IIS, so each inherits the parent connection string. We use a single copy of each application on the server. Can we deploy ASP.NET Core applications the same way?
I found StackOverflow articles on nested objects and environment specific AppSettings.json configurations but this does not appear to be the answer.
UPDATE 1:
The above is a multi-tenant configuration where each virtual directory is a tenant. The web.config at the root of each virtual directory contains the connection string all apps under the virtual directory use. 
I read that a web.config file must exist for ASP.NET Core apps to work under IIS.
https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/index?tabs=aspnetcore2x#webconfig-file
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?tabs=basicconfiguration#webconfig-file
So I wonder if that the connection string is visible to the ASP.NET Core applications.
Update 2:
A.F.A.I.K, web.config can be loaded from the app content root, but the one we need resides up in a virtual directory. A AspNetCoreModule maintainer told me environment variable inheritance (which applies in this scenario) is unreliable, and no plumbing exists to access other inherited configuration. The web.config only exists to configure IIS for ASP.NET Core applications.
The best solution seems to be using host headers the way Saaskit does.
https://github.com/saaskit/saaskit
This requires us to change our IIS deployment and add a DNS record per tenant, but it is the next best thing to inherited web.config files. I would like the ASP.NET Core team to consider introducing a ASP.NET Core-approach to inherited settings that gives us the same ability inherited web.configs did.
Putting tenant specific settings in a file up in a virtual directory is out of the box thinking, but it greatly simplifies multi-tenant support. Our MVC & Web API code needs nothing extra. It simply retrieves settings through the ConfigurationManager as though no other tenant exists.
We have one website under IIS and one virtual directory per tenant. Each tenant is accessed via its URI.
https://myfqdn.com/tenant1/myapp
https://myfqdn.com/tenant2/myapp
tenant1 and tenant2 are virtual directories containing a tenant specific web.config, so invoking https://myfqdn.com/tenant1/myapp loads tenant1's web.config and myapp inherits its settings for requests. /tenant2/myapp loads a different web.config.
Myapp is unaware of which virtual directory it was invoked from on each request. We install myapp in one physical location but add it as an application under each tenant's virtual directory. The result is we have one copy of the app, multiple instances, and no multi-tenancy plumbing.
ASP.NET Core is not bound to IIS so the same approach won't work as for ASP.NET. But you can implement a similar approach if you would like by moving your common settings to some SharedSettings.json and use this.
.ConfigureAppConfiguration((hostingContext, config) =>
{
var env = hostingContext.HostingEnvironment;
var sharedFolder = Path.Combine(env.ContentRootPath, "..", "Shared");
config
.AddJsonFile(Path.Combine(sharedFolder, "SharedSettings.json"), optional: true) // When running using dotnet run
.AddJsonFile("SharedSettings.json", optional: true) // When app is published
.AddJsonFile("appsettings.json", optional: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
config.AddEnvironmentVariables();
})
Read more here: Sharing appsettings.json configuration files between projects in ASP.NET Core

How do I host a public static site as a web app?

I want the url www.example.com to display default.html
From this question I understand that the easiest way is still to create a web app.
[How not to do it]
I tried creating a solution in VS2017
File->New ->Project -> .Net Core -> Asp.Net Core Web Application-> Empty
Then I moved my static files into wwwroot and deployed
What do I need to change so that default.html will load when someone goes to the site?
At the moment if I remove the Program class I get a message
Severity Code Description Project File Line Suppression State
Error CS5001 Program does not contain a static 'Main' method suitable for an entry point
which is understandable since it is a web application , how do I change it to be a static web site?
[A better way, create the app in Azure.]
Instead of the above method I created a new web app and followed the advise at this question to paste in index.html.
I can now go to the Azure url for the site and the correct content displays.
Next I need to get example.com to work.
I added the CName record for www in my DNS with the url for the site, and I also went to Custom Domains in Azure to add my domain name.
However I get the following error when I go to my site.
Error 404 - Web app not found.
The web app you have attempted to reach is not available in this Microsoft Azure App Service region. This could be due to one of several reasons:
1. The web app owner has registered a custom domain to point to the Microsoft Azure App Service, but has not yet configured Azure to recognize it. Click here to read more.
When an app owner wants to use a custom domain with a Microsoft Azure Web Apps web app, Azure needs to be configured to recognize the custom domain name, so that it can route the request to the appropriate server in the region. After registering the domain with a domain provider and configuring a DNS CNAME record to point to the app's Azurewebsites.net address (for example, contoso.azurewebsites.net), the web app owner also needs to go to the Azure Portal and configure the app for the new domain. Click here to learn more about configuring the custom domains for a web app.
I got it working in the end. I must have missed a step in the documentation

How to add more web apps to existing windows azure web site

I created a new web site on Windows Azure and chose WordPress from the Gallery to start the site. This is my company's website with my domain name. Now I want to add another web app from the gallery, let's say OpenX, on the same site so that it is running on the same domain. Does anyone know how to add another web app to an existing Azure website?
Create new web site. Each web site can use different subdomains.
Your original page can be www.domain.com for example, and the new one can be something.domain.com.
You just need to register the name server entry for each subdomain as you did for the original domain.
Yes you can create virtual directories. At the bottom of the Configure tab, there's a Virtual Applications and Directories section. Just create a new directory and check the Application checkbox.

IIS Website cannot access network share with the SAME app pool that is used by default website which does work

We have a production application (Classic ASP, IIS 7.5) that uses the IIS Default Website and a virtual directory. The application accesses documents from a document share. It works and has worked for many years.
Recently we have added a number of new web applications all under Default Web Site and we are attempting to separate them out into their own IIS Websites. So, we setup a new IIS Website and used a binding to get the application to use the new web site and used the same application pool pointing to the exact same code. (note: our application uses subdomains to point to different databases so we just took one subdomain and binded it to the new site).
For some reason, the documents that are accessible from the Default Web Site are not accessible in the new website. But given that both are using the same application pool and thus share the same application pool identity, how is it possible that one website can access the share, but the other cannot?
More info. we have tried using a domain user as the app pool identity and NETWORKSERVICE both of which work in the Default, neither of which work in the new web site. Also, how are we accessing the documents? We have an ASP file which simply uses the ADO Stream object and we reference the file using "\\docserver\documents..." (which again, is the same in both websites as they are both looking at the same code.

Point with N sub domains to one WebRole in Azure

Currently I'm trying to port a web application(ASP.NET MVC) to windows azure and have come across a point, I don't know how to solve.
The application is a multi tenant one. Every customer who registers, can enter a name for his instance and is able to surf the site later on over theenteredname.example.com. Further, the domain is used in an ActionFilter to switch between the databases.
How can I realize this in Windows Azure? I know that I must define a binding with defined hostHeader attribute, but as the subdomains a generated dynamically I would have to change the service definition every time a user registers and a new sub domain appears and redeploy it. But that is really not the way I want it.
Any help would be appreciated!
I think the problem is that IIS does not support subdomain wildcard mapping, see here Wildcard subdomains in IIS7. Is it possible to make them like it is in Apache? for more information.
If you would still like to do this there is a solution here http://www.seoconsultants.com/windows/isapi/subdomains/ , but it requires:
Ability to update DNS records
IIS web server admin access
ISAPI_Rewrite component (for Solution 2)
In Windows Azure, if you simply don't assign any host headers to your web role (which is the default), the site will be configured to accept any host header.
You still need to configure wildcard DNS to point to your Azure instance, just as you would for a non-Azure solution.

Resources