Putting a ASP.NET MVC web site in a subfolder - asp.net-mvc

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).

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.

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.

Best practices for deploying an MVC application on IIS7

I'm not a web admin, and I'm new to IIS. So, I'm looking for advice.
My MVC application (e.g. fooapp) is the default application for my site (e.g. foo.bar). I used IIS Manager to add the site to IIS7. When I import the application, IIS Manager wants to put it in it's own directory (/foo), and tells me I shouldn't put it in the base (site) directory. This means that to get to my default MVC view, I have to enter the URL http://foo.bar/fooapp/. Needless to say, I want to get there via http://foo.bar/
I see 2 possible solutions:
Add a default page to the site directory that redirects to the MVC app.
Ignore the IIS admonition and load the app into the site directory.
My IIS7 knowledge is limited. I have played around with some options (such as HTTP Redirect). Since nothing changed, I obviously don't understand what I'm doing.
Anyway, if there are some considered "best practices" and/or other suggestions, please let me know.
Tbh, I'm not sure why the IIS manager is trying to convince you to add it as a sub app.. Maybe you just didn't do it right >_>
I've got a couple servers running with IIS7/7.5 and they have apps running in the root of the website.. No problem there :)
You might want to create a new website in IIS (right click on websites, choose "Add Web Site"), point the "Physical Path" directly to the folder your website's stored in, and set the Host name to whatever host you use (foo.bar ? :) )
This should work just fine )
In terms of deployment, if you use VS2010 I'd really recomment looking at Web Deploy.. It's a new addon written for IIS7, and allows one-click publish to IIS directly from VS2010. I'm using it on my site and it works flawlessly :)
Check out Scott Hansellman's talk about it, or check it out in the IIS website

Integrating ASP.NET MVC 2 with classic ASP

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.

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