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.
Related
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.
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 .
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.
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.
I have a bit of a strange question. I'm building a multi tenant website with Asp.net MVC 2 and running it on IIS7. I'm trying to get my dev environment setup properly for testing but I'm having a weird issue though.
I created the website in IIS and pointed the directory to the location of my source code. I have just the basic HomeController along with an Index view setup. I have a binding in IIS on my website (and setup in my hosts file) for www.mydomain.com (this is so I can test the multi-tenant stuff).
When I run the site and I navigate to www.mydomain.com/home or www.mydomain.com/home/index everything pulls up fine. But navigating to www.mydomain.com gives me the IIS7 logo page. Is there something special I need to configure to get the root url to show me the Home/index page by default?
You need to configure a route like this:
routes.MapRoute("home", "",
new { controller = "home", action = "index" });
or this:
routes.MapRoute("home", "{action}",
new { controller = "home", action = "index" });
Your application must be running in IIS7's integrated pipeline mode. Otherwise you're going to need that default.aspx from the default ASP.NET MVC 1 project template.