A website is collection many webapplications? - c#

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.

Related

Transparently decomposing an ASP.NET Website hosted in Azure

I maintain a website written in ASP.NET MVC 5, and hosted in Azure. It's a legacy app that is a real nightmare to maintain, and so I've been asked to start migrating to a new codebase and the ASP.NET Core framework.
Our goals are:
Migrate one page at a time
Don't lose the "F5 debugging" experience in Visual Studio
My initial thought was to use a virtual application/directory, which is supported both in Azure and in IIS Express. The idea is to point, for example, the /Shop page to the new website by using a virtual path. Then when we're ready, move the /Team page and so on. I would add a virtual path for each migrated endpoint until the migration is complete.
To accomplish this I created a new ASP.NET Core project, and I've been trying to edit my applicationhost.config file and trying to start multiple projects from Visual Studio, without luck.
I tried configuring two sites with the same port binding, two apps within a <site> tag and also two virtual directories within an <application>, but I always end up with errors. Either I can't start debugging (Can't connect to IIS Express or The object invoked has disconnected from its clients messages) or I get a 502 error.
I don't even know if this is going to work in Azure, but I know we can't go down this path without proper development experience.
Am I missing some other, better solution? If this is a good solution, is there any way to make this work in Visual Studio?
I would consider creating multiple new websites in Azure, one for each section. Then, as I start working with Shop, for example, I'd leave an almost-empty controller in the original solution, redirecting to your new Sales web site. Using this approach, you can efficiently work with one smaller code base at a time and in the future scale the individual pieces of your site as needed. Please note, that you can host multiple sites within the same app service environment (thus not incurring a lot of extra cost by separating into multiple processes).
Best of luck :-)

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.

Assembly name for ASP.Net website project

I have Quartz.Net integrated for Scheduler job in my ASP.Net application.
But it is not working automatically and seems that it got stopped when IIS is recycling Application Pool. But fires when we send a request to server.
After reading IIS app pool recycle + quartz scheduling I am trying to configure the same in IIS 7.5 server for resolving the same.
<serviceAutoStartProviders>
<add name="PreWarmMyCache" type="PreWarmCache, MyAssembly" />
</serviceAutoStartProviders>
However PreWarmCache class has been defined in my website and kept all logic, since it uses template from website pages.
How can I define this class from website in type? What would be the value for MyAssembly ?
I can use assembly name if my project is web application.
I created as website. So what could be the value or how should I configure that section?
Note: PreWarmCache is placed under App_Code directory
This has nothing to do with Quartz.Net, but is to do with the IIS server recycling the application pool after a period of inactivity.
I have the same problem, but all I am trying to do is cache data.
So I need to do the following in my applicationHost.config file:
<serviceAutoStartProviders>
<add name="PreWarmMyCache" type="PreWarmCache, MyAssembly" />
</serviceAutoStartProviders>
This then call a function that populates an XML document and stores it as a lookup table in the cache to be used as and when needed.
And the problem is that if I use the AssemblyQualifiedName attribute it returns the following for my class:
MyApp.PreWarmCache, App_Code.<#########>, Version=0.0.0.0, Culture=neutral, PublickKeyToken=null
Where the ######### are, is changed each time the code is compiled.
I do not want to separate this into a DLL, as that would incur having to replicate the code.
So the question is still the same.
Can I/we provide an explicit assembly name for a dynamically compiled ASP.NET website's App_Code classes?
Fixed it now, taken code out into a separate assembly, compiled added reference, now all complete.
It is highly recommended that you do not use Quartz.NET in a web application. The application pools can, and do, reset. While they can be scheduled to recycle at certain times it's still possible for them to recycle at any time. This creates unpredictable behaviour and will be difficult to track down.
I highly recommend creating a Windows Service to handle your Quartz.NET tasks. It will be more predictable, easier to debug, and decoupled from your web application. This will remove the complexity of trying to keep the application pool on all the time to run a service.
If you still want to use Quartz.NET in your web application then this SO question may help.

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

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.

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