IIS7 / MVC4 Routing: Run different routes in separate app pools? - c#

Can I configure IIS7 to run the actions of two separate controllers under two separate routes in different app pools?
Using old .svc web services, I could separate service calls by having a separate .svc file under a particular directory, whereby I could make the directory a Virtual Directory allowing me to run the service as a different identity (or with different authentication settings). This gave me the ability to have a single code base deployed to separate web structure locations.
I now have a single MVC (/WebApi) application, with multiple service APIs. Some of these service calls have to be run in a different app pool from the rest for security purposes.
Despite being separate service methods on separate routes within the application, IIS only sees it as a single application, and (apparently) has no way to map the virtual routes within MVC to Virtual Directory settings.
Creating a separate MVC application and hosting it in a Virtual Directory under the root site causes issues around web.config inheritance, which again I haven't found a way around.
Having said all this, my knowledge of IIS7 is very limited, and googling just brings up posts based on keywors that don't cover this particular scenario.
Would appreciate any help.
Regards,
Rob.

Web.config is inherited in directories and virtual directories, but not across applications. Please make sure your subdirectory is set up as an application (right click on parent, select add application or right click on sub directory and select "convert to application"). At this point each application has it's own web.config file.

Related

How to map sub site requests to the parent site?

We've got one monolithic ASP.NET application at, say, https://my-site.com.
Inside it there is a number of controllers at path /api, say,
https://my-site.com/api/user
https://my-site.com/api/order
https://my-site.com/api/cart
Now we're trying to split the monolith into separate services. These services are separate .NET Core applications. And they are going to gradually replace all those controllers in the /api path. So while some controllers in the monolith should still be working, we need to add separate applications to handle requests for, say, https://my-site.com/api/user.
The site is hosted in IIS. If we create a sub application api for the https://my-site.com site , IIS starts mapping all requests to /api/whatever to the api sub application and not to the parent site. How can we make IIS map requests only for paths really present in the api sub application while mapping others to the parent monolith?
What we've tried so far...In web.config of the monolith in system.webServer we added an entry to the handlers section like this:
<add name="api-order" verb="*" path="api/order*" type="Monolith.Controllers.Api.Order" preCondition="managedHandler"/>
With this we wanted to make IIS map /api/order requests to the monolith and thus ignore the existing api sub application.
However it turns out that IIS chooses the sub application at first and checks its web.config already after that.
So is there any way to cheat IIS and make it map only certain requests to the api sub application?

ASP.net mvc routing with multiple sites under the same route url

Good morning,
I have a fairly large MVC project with 30/40 controller and a lot of views, i am trying to publish on IIS using multiple application so i can split various sites per different customer.
I want to use my landing page as the base url:
https://somewebsite
I then want to host multiple applications (e.g the same project with different config) as separate applications but under the same main host name.
https://somewebsite/Customer1
https://somewebsite/Customer2
Now i can get my multiple websites fine under the seperate host as application, but when i add my landing page (as the full application) its corrupting the other two sites.
My thoughts are that the routing in the route app (the one i want just for landing page is causing the issue).
Any ideas?
If you are deploying via WebDeploy it will delete subfolders under the host site if they are not part of the host application. You can disable this behavior however with a MSBuild argument:
/p:SkipExtraFilesOnServer=true
OR during the MSDeploy deployment using the following argument:
-enableRule:DoNotDelete
http://www.dotnetcatch.com/2016/02/01/webdeploymsdeploy-quick-tip-keep-existing-files-during-deployment/
The issue lay within the web.config of the applications. The config was being inherited from the master site and causing issues across the board.
Set the clear attributes in the child application config and all is well with the applications.

A website is collection many webapplications?

I just heard a very experienced .NET instructor say that a website is a collection of many webapplications and for every webapplication there is a AppDomain.
Does webapplication in this context mean webforms?
In IIS, a "Web Site" is what is tied to a specific host name and port. That web site can contain one or more "Web Applications", which is what can be created in ASP.NET. Each "Web application" is isolated from the others and contains it's own global.asax, sessions etc.
The isolation is not total though, web.config settings are inherited to sub directories. Applications sharing the same app pool can interfer with each other (the sandboxing is not perfect)
A website consists of one or more projects (one could say webapplications, however I think that is confusing terminology), each getting compiled to an assembly. Before the code in an assembly can be run it needs to be loaded into an application domain (AppDomain), which is an isolated piece of memory in which the code will run.

Host 2 seperate MVC websites under 1 url

I have 1 secure MVC website already hosted at say https://mysite.co.uk. This website has areas, controllers and actions as per normal:
https://mysite.co.uk/kitchen/create
https://mysite.co.uk/bathroom/edit
etc
Initially, I was told that my second MVC website would be able to be hosted under a new url: https://mysite-newsite.co.uk, so I have a new solution with.
But now unfortunately the deployment team have said it needs to be deployed under the initial main url:
https://mysite.co.uk/newsite
We are using iis7 and I have tried to achieve this using Add Application , but I just run into lots of problems with routing, nhibernate dll conflicts etc.
Can this be actually be resolved somehow in iis7 please? Or will the second MVC solution need to be re-written somehow?
Thanks
I think your best bet would be to create a sub-directory in the first application's deployed directory and put the second application there.
You can then set the sub-directory to be its own application in IIS and they will operate independently.
So, you will have url's like this:
https://mysite.co.uk/kitchen/create <-- first site
https://mysite.co.uk/[subdirectory]/controller/action <-- second site
The route urls in the second application should work, but you will need to check this.
Otherwise, you will have to merge the two applications into one solution.

ASP.net MVC 4 web application with web service sharing its code

I have written a MVC web application that is used on our corporate intranet. We also have an MVC web site that is a seperate web application that is used by our customers. For our website to talk to our intranet systems database I have written a c# web service to access it.
The problem I have now is in the intranet application I have a complex routine that does some calculations that I now need in the web service for the website to do the same thing. I do not want to copy the logic and have it repeated in 2 locations for obvious reasons, so I need the web service and web application to share the same code base. I know this is possible but what is the best was to go about the use of application variables stored in web config files. For example if I move the code out of the intranet app and into a class library I will loose the functionality of being able to access the webconfig file, so where do I put these variables?
Any Suggestions on the best way to do this?
I will loose the functionality of being able to access the webconfig
file, so where do I put these variables?
You won't loose that ability. Every part of your application can access the configuration file, for instance by using the ConfigurationManager.AppSettings property.
Put the shared code in a class library that is referenced from both the web site and the web service.

Categories

Resources