I have created a MVC application using vishal studios 2008. I want to host this on my local machine.
I have copied my whole project folder into the Inetpub\wwwroot folder. I then created a virtual directory from IIS.
When i access my site localhost/ReleaseTrackingSystem it doesnt run my application, instead it shows me all the files within the ReleaseTrackingSystem folder in wwwroot. So its only displaying all my files with the date, time, size or whether its a directory,
and the name of the folder/file.
Why is this? how can i get it to actually run my application?
It does sound like you are using iis6 and what is happening is that a request is coming in without the .mvc extension, iis then looks for a default document, doesn't find it, and then lists the contents of the directory, since directory browsing is enabled.
You should add a file "default.aspx" to your project, in the code behind, redirect to home.mvc or some default controller. You can see an example of this if you create a new mvc project out of the box.
Joe
Marked as answer by vmb2000_uk on Jul 22, 2008 01:57 PM
If you're in control of the machine and have access I would suggest using an ISAPI filter, check out Ben's post here: http://www.flux88.com/UsingASPNETMVCOnIIS6WithoutTheMVCExtension.aspx
I personally find extensions like .mvc and .rails a smell. If you care enough to use rails or mvc, care enough clean your urls. I am using ISAPI Rewrite. If you want to rewrite using the ISAPI rewrite, I can share my config with you.
If you've found this post helpful, please mark this question as answered.
Ive just checked the IIS version and its V5.1, not 6. I would prefer having 6. I tried downloading IIS 6 from the microsoft website. Is it "Internet Information Services (IIS) 6.0 Manager for Windows XP", well i download this and installed it.
If i go back to run "inetmgr" it shows the version still as 5.1
Even if i leave it as 5.1 do i still change the default.aspx?
public class
GlobalApplication : System.Web.HttpApplication
{
public static
void RegisterRoutes(RouteCollection routes)
{
// Note: Change the URL to "{controller}.mvc/{action}/{id}" to enable
// automatic support on IIS6 and IIS7 classic mode
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
// Route name
"{controller}.mvc/{action}/{id}",
// URL with parameters
new { controller =
"Home", action =
"Index", id = "" }
// Parameter defaults
);
routes.Add(new Route("Default.aspx",
new MvcRouteHandler())
{
Defaults = new RouteValueDictionary(new { controller =
"Home", action =
"Index", id = "" }),
Ive realised another problem. in my global.asax i didnt have the .mvc in the routing.
When i add "{controller}.mvc/{action}/{id}" my application stops working in visual studios itself, before adding this line my application worked fine. When i run the application i get the following error:
Server Error in '/' Application.
The resource cannot be found.
Description:
HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
hello again. well, you need to set all rules to use the mvc extension and then you need to generate the correct url for the buttons (which must also include the mvc extension). Are you using the helpers for getting the correct urls?
--
Regards,
Luis Abreu
email: labreu_at_gmail.com
EN blog:http://msmvps.com/blogs/luisabreu
Marked as answer by vmb2000_uk on Jul 22, 2008 01:57 PM
vmb2000_uk
Member
15 Points
35 Posts
Hosting MVC Application on localhost
Jul 15, 2008 08:24 PM|LINK
HI,
I have created a MVC application using vishal studios 2008. I want to host this on my local machine.
I have copied my whole project folder into the Inetpub\wwwroot folder. I then created a virtual directory from IIS.
When i access my site localhost/ReleaseTrackingSystem it doesnt run my application, instead it shows me all the files within the ReleaseTrackingSystem folder in wwwroot. So its only displaying all my files with the date, time, size or whether its a directory, and the name of the folder/file.
Why is this? how can i get it to actually run my application?
Regards,
Vishal
jbardrof
Member
638 Points
192 Posts
Re: Hosting MVC Application on localhost
Jul 16, 2008 12:38 AM|LINK
I'm guessing you are using IIS 6?
if so, go to your global.asax page and change your route to: {controller}.mvc/{action}/{id}
If that is not the problem please give more details as to what version of IIS you are using, and what steps you took to deploy your site.
joecar
Member
524 Points
120 Posts
Microsoft
Re: Hosting MVC Application on localhost
Jul 16, 2008 06:34 PM|LINK
It does sound like you are using iis6 and what is happening is that a request is coming in without the .mvc extension, iis then looks for a default document, doesn't find it, and then lists the contents of the directory, since directory browsing is enabled. You should add a file "default.aspx" to your project, in the code behind, redirect to home.mvc or some default controller. You can see an example of this if you create a new mvc project out of the box.
Joe
Fevir
Member
657 Points
151 Posts
Re: Hosting MVC Application on localhost
Jul 16, 2008 06:43 PM|LINK
If you're in control of the machine and have access I would suggest using an ISAPI filter, check out Ben's post here: http://www.flux88.com/UsingASPNETMVCOnIIS6WithoutTheMVCExtension.aspx
I personally find extensions like .mvc and .rails a smell. If you care enough to use rails or mvc, care enough clean your urls. I am using ISAPI Rewrite. If you want to rewrite using the ISAPI rewrite, I can share my config with you.
vmb2000_uk
Member
15 Points
35 Posts
Re: Hosting MVC Application on localhost
Jul 16, 2008 09:30 PM|LINK
Hi,
Ive just checked the IIS version and its V5.1, not 6. I would prefer having 6. I tried downloading IIS 6 from the microsoft website. Is it "Internet Information Services (IIS) 6.0 Manager for Windows XP", well i download this and installed it.
If i go back to run "inetmgr" it shows the version still as 5.1
Even if i leave it as 5.1 do i still change the default.aspx?
vmb2000_uk
Member
15 Points
35 Posts
Re: Hosting MVC Application on localhost
Jul 16, 2008 09:44 PM|LINK
Hi Guys,
Just to let you know i have tried your suggestion:
1) add .mvc/{action}/{id} to the global.asax file.
Also here is the code for my default.aspx, is this correct?
using
System;using
System.Collections.Generic;using
System.Linq;using
System.Web;using
System.Web.Mvc;using
System.Web.Routing; namespace ReleaseTrackingSystem{
public class GlobalApplication : System.Web.HttpApplication{
public static void RegisterRoutes(RouteCollection routes){
// Note: Change the URL to "{controller}.mvc/{action}/{id}" to enable // automatic support on IIS6 and IIS7 classic mode routes.IgnoreRoute("{resource}.axd/{*pathInfo}");routes.MapRoute(
"Default", // Route name "{controller}.mvc/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = "" } // Parameter defaults);
routes.Add(new Route("Default.aspx", new MvcRouteHandler()){
Defaults = new RouteValueDictionary(new { controller = "Home", action = "Index", id = "" }),});
}
protected void Application_Start(object sender, EventArgs e){
RegisterRoutes(RouteTable.Routes);
}
}
Regards,
Vishal
}
vmb2000_uk
Member
15 Points
35 Posts
Re: Hosting MVC Application on localhost
Jul 17, 2008 08:27 PM|LINK
Ive realised another problem. in my global.asax i didnt have the .mvc in the routing.
When i add "{controller}.mvc/{action}/{id}" my application stops working in visual studios itself, before adding this line my application worked fine. When i run the application i get the following error:
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.Requested URL: /Release
Any suggestions???
Vishal
Luis Abreu
All-Star
25674 Points
5369 Posts
MVP
Re: Hosting MVC Application on localhost
Jul 17, 2008 08:34 PM|LINK
Regards,
Luis Abreu
email: labreu_at_gmail.com
EN blog:http://msmvps.com/blogs/luisabreu
vmb2000_uk
Member
15 Points
35 Posts
Re: Hosting MVC Application on localhost
Jul 17, 2008 08:58 PM|LINK
Hi, Thanks so much for that.
The main page runs fine which is http://localhost:4915/Release.mvc
But for example i have a button which is add release and when i click this it navigates to: http://localhost:4915/Release/AddRelease
but if i manually type in http://localhost:4915/Release.mvc/AddRelease it works fine.
Is there another place in the code i have to update to make this work?
Luis Abreu
All-Star
25674 Points
5369 Posts
MVP
Re: Hosting MVC Application on localhost
Jul 17, 2008 09:07 PM|LINK
Regards,
Luis Abreu
email: labreu_at_gmail.com
EN blog:http://msmvps.com/blogs/luisabreu