MVC 5 in VS2012 - asp.net-mvc

I have installed ASP.NET and Web Tools 2013.1 for Visual Studio 2012 which has the MVC 5 templates for Visual Studio 2012. In Project Templates I am able to find the "ASP.NET MVC5 Empty Project" however after creating the Project, if I try to open the same project in the Internet Explorer by Pressing Ctrl+F5 it gives an error saying,
Server Error in '/' Application.
But When I create a MVC 4 Web Application and try to run it the Application works fine and shows the default page of the MVC 4 App.
Is there any other configuration needed to be done on the Visual Studio 2012 to make it run?

An Empty application is just that. Empty. There is no default page. It's an empty project that you have to create the content for.
Microsoft did not supply a default application template for MVC5 in VS2012. VS2013 does have a default template though.

Since it is an empty template it doesn't have a landing page and hence it was throwing the error
Server Error in '/' Application.
if you append the Controller name and view name just like below
localhost:port/[Controller]/[View]
It will show the contents of view.

you can try either edit your routing.config file, or change your url. Usually it will default to index.
This is an example of a route you can maybe add in as a class, if you do not have one already. This controller just means that it defaults to the Home controller, at the action called index.
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
I hope this somewhat helps .

Related

IIS 6.1 shows directory listing instead of MVC 3 app

I have just finished development in ASP.NET MVC application and I try to deploy it to a web server. The problem is I only see the content of directory, not the start page. Here is the visual explanation:
Things I did are publishing my MVC site, create a new folder in test server, I create a web site and copy files of publication to test server path.
my .NET Framework version is 4.5.2. MVC version is 4.
Any help is appreciated.
Edit 1:
In the comment below there is a recommandation of seeing "IIS 6.0 suddenly shows directory listing instead of MVC 3 app".(Link: IIS 6.0 suddenly shows directory listing instead of MVC 3 app) None of them solves my problem.
Edit 2:
Here is the content of the RouteConfig file:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
I have solved the problem and I want to share the solution with you.
I have done everything that described at the links, but I could not solve.
The first server's operating system I have been trying to deploy is Windows Server 2008 R2 Enterprise, and it does not contain any MVC applications, it only contains web forms applications.
The successful deploy has been made in Windows Server 2012 R2 and there are many MVC applications inside. The program ran successfully there. I presume some modules shall be installed in application server.
Hope this helps.

404 Error with Durandal Starter Kit and Visual Studio

I have just installed the Durandal Starter Kit via Nuget and was hoping to start building Durandal apps using Visual Studio and the MVC framework. I've read a couple of articles and blog posts like this but whenever I try and set up a sample Durandal application I get a 404 error with the browser complaining: 'The resource can't be found.'
I've checked and the Nuget installation has set up DurandalController.cs and deleted the default MVC controller. The project was created as an 'ASP.NET MVC 4 Web Application' using the 'Empty' template. What am I doing wrong?
The problem was that the installation of the Durandal Starter Kit had created a new default controller but hadn't set it as the default route for the project.
To fix it, I navigated to App_Start/RouteConfig.cs and in RegisterRoutes() I changed the default routes.MapRoutefrom:
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
to:
defaults: new { controller = "Durandal", action = "Index", id = UrlParameter.Optional }
The application worked straight away after this change.

ASP.Net MVC Application cannot find home index page on the server

I deployed a MVC web application with razor view to godaddy.com. My application works fine on localhost, but after deployed, it cannot route to my home page when I typed in the domain name. I have the following route registered in my Global.axcs file.
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "HomePage", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
Godaddy's technical supports asked me to add an index.html file in the root. I did add one and comment the default route in Global. And it loads the index.html. But I really want to display my /HomePage/Index
Does anyone know why this happens, and any suggestions?
I also faced a similar issue in the past.
One issue here might be that your server does not have MVC installed (as in my case).
Resolution : I followed the post to bin deploy the MVC assemblies together with my web application.
http://haacked.com/archive/2011/05/25/bin-deploying-asp-net-mvc-3.aspx
It worked for me.
Give it a try and I think it should work.

Using Cassini with a virtual path that contains dots

I am working on an existing project in ASP.NET witch is based in a folder that contains dots
http://localhost/My.Awesome.WebClient/
This setup works fine using the integrated Visual Studio Develompent Server, but fails when I add MVC content and try to access it (Error 404 Resource not found).
http://msdn.microsoft.com/en-us/library/ee941656.aspx seems to explain the issue:
If you create a file system Web site in Visual Studio 2010 and the Web site is in a folder that contains a dot (.) in the folder name, URL routing will not work reliably. An HTTP 404 error is returned from some virtual paths. This occurs because Visual Studio 2010 launches the Visual Studio Development Server (Cassini) using an incorrect path for the root virtual directory.
However, the project is a Web Project, not a Web Site, and it only failed when I started using MVC.
The problem can be easily reproduced:
File - New - Project - ASP.NET MVC 3 Web Application
Edit project settings, Web: Use Visual Studio Development Server
Set the virtual path to something that contains a dot
Try to run the site
Is there a way to get this to work, besides using IIS instead of Cassini?
Edit:
I did find a workaround just now. It does not really work in a deployment scenario, but it may help in finding a solution:
in my Global.asax.cs file:
routes.MapRoute(
"Default", // Route name
// Notice that I added the virtual path here
"My.Awesome.WebClient/{controller}/{action}/{id}", // URL with parameters
new { action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
// This is also new
routes.MapRoute(
"Root", // Route name
"", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
Using this workaround, my MVC-Sites work, but only with the following url:
http://localhost/My.Awesome.WebClient/My.Awesome.WebClient/
If you don't get an answer to this question (personally, I'm not aware of any way around this), I would recommend using "IIS Express", which is available as a free download. It can be installed on development machines and you can control a lot of server settings with your web.config file, which is fairly unobtrusive.
You can download it here:
http://www.microsoft.com/download/en/details.aspx?id=1038
I use IIS Express exclusively now; Cassini has always lacked features and IIS Express avoids me having to configure IIS for each web application.

blank pages/routing issue with asp.net mvc 2 iis7 integrated windows7 vs2010

I've been searching though a number of posts and still can't seem to get a straight answer or at least one that works for me. From what I can tell is is some kind of routing issue. In fact I'm pretty certain of it. When I visit any of my web pages it comes back as a blank page with no data.
Also I am using VS2010 asp.net mvc2 on window7 using iis7 integrated. The purpose of using iis7 integrated is because when I publish the site to my godaddy hosting provider I want to be able to replicate the security permissions locally so after publishing the site should not have any surprise issues that pop up.
I tried using the Default.aspx trick described here ASP.net MVC on IIS 7 returning blank page but the same problem only the root page gets displayed and no other routes are available.
I have also tried crating a empty route described here
routing to blank request in mvc asp.net using IIS 6.0
and here
I am getting a blank page while deploying MVC application on IIS
I am also using the Route debugger found here
http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx
Using the Route debugger when I visit http://localhost/ I still get a blank page with no data. But When I visit http://localhost/Home.aspx the route debugger then kicks in and displays the fallowing
http://j.imagehost.org/0476/routes.png
When I add
routes.MapRoute("Default2", "", new { controller = "Home", action = "Index" });
above or below the catchall route
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }); // Parameter defaults
it does the same thing blank page when I visit http://localhost/ I still get a blank page with no data. And when I visit http://localhost/Home.aspx the route debugger kicks in and displays the fallowing
http://a.imagehost.org/0115/routes2.png
Is there anything else that I can try to get my pages to display properly? Seems like a lot of people are having the same issue but with iis6 classic or older mvc versions have have seen very few posts about people having blank page issue with my configuration of VS2010 asp.net mvc2 on window7 using iis7 integrated.
Any help is greatly apreciated!
"HTTP Errors" and "HTTP Redirection" services must be added to "Web Server (IIS) role. If you wan't to get static content like CSS and Javascript working, too, enable "Static Content" service as well.

Resources