Integrating ASP.NET MVC 2 with classic ASP - asp.net-mvc

I'm in the process of moving a large classic ASP application to ASP.NET MVC 2. Questions:
My question is about project organization.
I would prefer to not mix the MVC code with the ASP code in the same VS project. I'd like to have an MVC WAP with areas that match the parts of the website that I'm migrating. For instance, the old site has a folder
/products/default.asp.....
/products/productName/default.asp
etc.
In the MVC WAP, I'd like to have an area called "products", which I could then, either through a rewrite, routing, or preferably through some IIS configuration, point the "products" folder on the ASP site to. In this way, I could gradually move root folders from the ASP site to the MVC application.
However, if I create the MVC WAP in a virtual folder, then my routes wind up looking like
http://localhost/virtualFolder/products
instead of
http://localhost/products
Any suggestions on how to conquer this?
I know that, during deployment, I could deploy the MVC WAP into the root of the ASP site, but this doesn't help with debugging.

I'll write my answer assuming this is hosted on an IIS7 instance. If it's IIS6, then you'll need to look for a suitable ModRewrite module for it.
So, assuming IIS7, you'll be far better off using URL Rewrite:
http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module/
You can manage your rewrite rules and rewrite maps, depending on your level of access and control, either from within the IIS7 Administration Console, or manually via your web.config file.
These rewrite rules and maps can be as simple or complex as you need them to be. You can also set them up to be either a temporary or permanent redirect - which will assist if any search engines are indexing the site as the correct redirect code will be returned with the HTTP request to ensure crawler results are updated promptly.

Related

ASP.Net MVC and Web Forms applications using same domain name, but code is kept in separate solutions

I have an old web forms application (.net 3.5) hosted at www.business-app.local
I want to build a new ASP.NET MVC (.net 4.0/4.5) application that will also have the domain name www.business-app.local
I know I can't have two applications with the same domain and port on IIS.
I have tried adding the MVC app in a virtual directory but hit a bunch of web.config clashes.
I want to keep the two applications separate, i.e. it is not a solution to just add the web forms pages to my MVC application, or to add MVC to the web forms application.
How can I achieve this using IIS 8?
The easiest way to do this is to create your new MVC app and add the folders containing the webforms into it. Queti mentions doing this the other way around, but honestly, it's a massive PITA, as you have to hack around with config files and references.
Once you have your webforms pages in specific folders in the MVC app, simply add exclusions for them from routing in global.asax.cs like so:
routes.IgnoreRoute("Webformsfolder/{*pathInfo}")
Also, seeing as you are (I presume) phasing out the webforms stuff eventually, it's probably best to start from scratch anyway, IMHO. Good luck!
You could add MVC to the current application. The trick is to make sure that the routes do not conflict with the web forms directories otherwise the WebForms will be the ones that handle the request.
This is the process I've followed when migrating Web Forms sites to MVC.
I have had to compromise and put them two apps on separate sub domains with a common cookie.

Mapping .css and image files through asp.net even with Integrated Pipeline and asp.net MVC 3

I've got some complex routes setup in my asp.net mvc 3 project, unit tested and working on development. For the most part they're working with IIS7 and Integrated Pipeline and having mapAllRequests=true.
But I'm also doing some funky routing with 'some' of the requests for images and css. I'm not sure if it's the logic or if it's IIS taking over when it see's css or img files. I want IIS to take over if it finds the static file otherwise send it to the mvc routing, is this possible?
Not with app pool in integrated mode - all requests are passed to the application. By default, MVC does not route requests for static files (it maps url-paths to them just like non-mvc asp.net, which is the behavior that you want).
You can change that behavior (routes.RouteExistingFiles = true) if you want to do something special within responses to static files. More info about this property:
ASP.NET MVC RouteExistingFiles question
Considerations when turning on RouteExistingFiles
http://msdn.microsoft.com/en-us/library/ie/cc668201.aspx
I hope this helps.

Hosting an MVC and a webforms site on the same IIS7 instance - web.config inheritance

We have a website that was written in classic ASP, then I started to extend it using web forms. These extensions exist in a subfolder of the main folder. Now we've decided we'd prefer to use MVC3. Also, as we'd like to convert all our site to MVC3 over time, we are hosting the MVC code in the application root. I've found some other questions where people have a similar issue to mine, but no solution. The issue is simply that my web forms app can't seem to be stopped from inheriting the web.config settings from the root folder, and as a result, it won't run, it either complains about missing dlls, or complains about running the wrong version of .NET, or complains I need to remove some settings ( which I try and can never get to work right ). The app in the subfolder is also hosting a webservice that is called by our application, and it also runs HTTP handlers to protect our imaging content, so it's got a bit of stuff in it. Do I need to run my MVC site in a subfolder ? Is there any way to have MVC in the folder above a web forms app ? I'd prefer to set things up so they share session data, but that's looking likely to be impossible at this stage...
So to be clear the folder structure is:
<root>
contains asp site and MVC site.
<subfolder>
contains webforms application
</subfolder>
</root>
and my issue is getting the subfolder to run, preferably in the same session as the MVC app.
There is no reason you can't run regular .aspx files on an MVC site. You are correct though, web.config settings are inherited from the parent (chain), but you just add a new web.config in your directory with relevant settings.
What you will have to do is play with the routes, because by default MVC will route all requests into your controller classes. But if you google around its fairly simple to add an exception to the routing.
If you post some of the specific errors we can probably help further.
Oh and do you mean Classic ASP? i.e. not Classic ASP.NET? Because you'll have fun sharing session data between ASP & ASP.NET.

Putting a ASP.NET MVC web site in a subfolder

For a shared test environment I need to place an ASP.NET MVC 1.0 web application in a subfolder. So the URL to the web applications start page will look something like http://192.168.100.1/webapp1/.
Is this possible at all or must it always reside in the root?
Er yes- just create a virtual directory. Let us know if you want any further info (I suggest you try Google first though).

Asp.Net MVC on Subdomain, standard MVC app gives 404's

I am trying to deploy my MVC app on a subdomain, unfortunately I get 404 errors.
I tried to find out if it's MVC itself that can't handle being hosted on a subdomain.
I uploaded the standard bare MVC webapp that you get when you start a new project. The index page loads, but all the other pages that require actual routing based on the url do all give 404's.
What do I need to change to be able to use MVC on a subdomain.
(it's all setup on a IIS 7.5 server as a seperate website)
I had this problem with a shared hosting provider. I had to get them to change the Application Pool to "Integrated Mode" instead of "Classic" mode in iis7 for it to work. Not sure why, haven't really looked into IIS7 that much
Is this a shared host where the subdomain is resolved via URL rewriting to point to a sub folder?
MVC doesn't care what the domain name is. I've used it with a couple different subdomains, but they were not on the type of host that would be rewritting to a sub folder.

Resources