Multiple Global.asax files per web application project - asp.net

I have existing web application project in which i need to add new subdirectory. In this subdirectory i need to add WCF service.
Question is: Can i use different AppDomain then services from root directory? Also, can i add new global.asax just for this subdirectory?

There's nothing in your question that wont stop you from defining the subdirectory as a new web application within IIS, thus allowing you to create new global.asax/web.config. Just remember that the web.config configuration is inherited by default, and you'll need to remove any handlers that your parent site added, but your subsite does not have.

When you are in the situation that the global.asax file has to be different then you are almost always better off splitting the service out to it's own project and deployment location.
This way changes in the main site won't impact the web service.

Related

ASP.NET Virtual Path Maps To Another Application Which Is Not Allowed

I have a website that was building without any issue on multiple servers.
But, when I copy/move it on the same machine from one folder to another folder: I started getting the error
The Virtual Path Maps To Another Application Which Is Not Allowed.
What am I doing wrong?
The source of this problem is that when one copies an ASP.NET Web Site to a new folder -- the properties setting associated with the solution "Virtual Path" is set to the folder name and not the root. The solution is to change the Virtual Path setting from the folder name to "/".
This can be found by right click the project and opening the properties dialog: Solution->Properties->Virtual Path-> Change to "/"
This isn't why your error happened but it may be useful to someone researching the problem who ends up here.
If your web app is running as an application within another IIS site (set via the IIS administration tool) and is attempting to reach resources of the other site by means such as HttpResponse.Redirect, make sure the project isn't set to use a separate IIS in Visual Studio. If it is, it may be firing up inside a different IIS than the rest of the site.
Additional check: Missing global.asax also causes the same error.
If you are creating a new HttpContext and calling any external
service, it also causes the same error.
Key is you should not create new HttpContext, change the existing
context to your needs.

How to nest ASP.NET websites

Is it possible to nest one ASP.NET website within another, for example:
http://example.com is an application root
http://example.com/differentsite is also an application root
If it is possible, what should be stuck in the web.config file of the parent website to prevent it interfering with the child site?
Note: This is for .NET 4.0 shared IIS7 hosting
Thanks in advance
Right click on the nested folder is IIS manager and click on "Convert to Application". This way they can live together. If you want them to run in separate processes so they won't have the same Application Pool settings, Create another application pool and assign one of the sites to it.
BTW, if the site folders are nested, they don't have to always appear in IIS manager as nested. You can add application to the default web site (or create a new site) and point it to the nested folder.
Yes, you can nest web sites by making folder an application, or adding a virtual folder that points to another application.
You need access to manage IIS on the server to do that, though.

Running a website in a sub-folder using a separate web.config?

I was wondering if it is possible to run an aspx.net website in a sub folder if it has it's own web.config with forms auth and is using a role mananger?
I've done this for nested applications recently. Its not too difficult.
In addition to having access the same data store for credential and role data, you need to:
make sure the the machineKeys are the same for both web applications
configure loginUrl's to resolve to the same absolute path
if you're using cookies you need to make sure that the domain is set to a value available to both web applications
also for cookies, if your web applications are nested at diferent levels in a domain make sure that the path attribute is set to "/"
See this blog post for more detail on getting forms authentication working.
Another issue particular to nested applications is that by default your nested web.config will inherit settings from the parent app's web.config. This means that you may need to strip out some items in the child config that are in the parent config, and remove items that are currently in the child app config but would already be present in the parent config. See this for more detail.
Only if you setup this sub directory as different asp.net application from iis
I think there won't be any problems if you use Virtual Directory. Look here for more info:
http://msdn.microsoft.com/en-us/library/zwk103ab(v=vs.80).aspx
http://www.dotnetspider.com/tutorials/AspNet-Tutorial-86.aspx
Is this what you were looking for?
Authentication can only be set in config for all applications, or root folder of web application. Same for setting session. You can use sub folder. But it has to be its own application , so basically it doesn't make a ton of sense to have it as subfolder of another application.

IIS7 Application Configuration

I have a custom ASP.NET application that I utilize for several clients that I host. Each client has a separate domain and the application is normally a child application under the root domain (http://domain.com/customapp). The application files are the same (aspx, ascx, style sheets, images, etc.). The only thing different is the web.config file for each client. As development of the application continues to evolve, I have to update the application for each directory and this obviously becoming tedious. I am trying to come up with a method keep the application up to date. My first though is placing the application into a single physical path and creating multiple applications pointing to that path (the problem with this method is I can't have different web.config files). I am curious as to what solution others are using in this scenario...
If you want to handle this entirely in Visual Studio, VS2010 offers web.config transforms which could solve your problem.
In a nutshell, create a build configuration (In VS, select Build|Configuration Manager...) for each site. Add a web.config transform for each client, which only specifies the differences required for each application.
I use this for differentiating between development, staging and release configurations - each transform adjusts the connection string, app settings, etc - and it works quite well both within Visual Studio and when deploying via MSBuild.
Also, note that web.config settings are inherited by IIS applications. So, if you have a root site
/root
and client apps
/root/client1
/root/client2
...
you could place the client-specific config settings in a web.config in each client-specific folder, and global settings a web.config in the root folder.
Can you just move your web.config content to a database and load it conditionally based on the domain that was referenced?
Select Case Request.Url.Host.ToLowerInvariant()
Case "xyz.com", "www.xyz.com"
'Load XYZ stuff'
Case "abc.com", "www.abc.com"
'Load ABC stuff'
Case Else
'Throw an error probably'
End Select
Even better, store your domains in the database as keys so that you don't ever have to touch the code.

web.config in nested folder

I am trying to install an app inside of another web app. I have my .aspx pages and some code that I was putting into the main app's app_code folder. I've added my own web.config file for my connection string and such but I think there's a conflict. So my question is a two parter. First, what is the best way to install an app inside of another app, i.e should I use the main apps app_code folder or add my own, and second, would there be a conflict with the two web.config files. I was under the impression that the files pulled from the most specific web.config file. It appears there is a problem with my security and I am unable to access my file. I was attributing this to the two web.config files,
thanks.
If the nested application has had its folder turned into an application (right-click on it in IIS, Properties, and on the "Application" tab, "Create" a new application), you should put the code in the local App_Code folder:
- \RootFolder // Root of website
|- \App_Code // App_Code at root
|- \NewApplication // Seperate application in IIS, has "web in a box" icon in IIS
| |- \App_Code // App_Code of new application
If the nested application isn't a true application (in the IIS sense), then you will need to have the code files in the root App_Code folder.
This also has a bearing on your web.config - if the nested application is a true application, then you'll be able to have a full web.config at the level you want - however if it's not an IIS application, then there are limitations as to what you are able to put in subsequent web.configs - some elements are only allowed in the web.config at the application root, and can't be overridden by other settings.
What's the actual error you are seeing?
Regarding your first question, I would rather have them deployed on different folder. And second, if you have, for instance, a web site inside the default web site, you will have both web.config, but the more specific will override some of the attributes of the web.config from the default web site, but the ones that are not override will be there, (ie, HTTPHandlers, HTTPModules, the site will try to load those, so you will need to add the remove tag inside the HttpModules to remove them).
Hope this clarify your question

Resources