简体   繁体   中英

Resource cannot be found (MVC)

I moved a solution from one machine to another and am having nightmares. I've got one problem left. The default page can't get served, it says Resource cannot be found. I have in the routeConfig.cs

routes.MapRoute("Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional });

I get Resource cannot be found.

I can access the default page by :-

http://example.com/home/index

The other questions don't seem to answer it.

EDIT: If I put the above line of code at the top of the Routing code, the default page works but other pages don't. If I put the code at the bottom, other pages work but the default page doesn't.

尝试查看属性,如果您选择了服务器和项目URL,希望有一个“ Web”选项卡,希望

If you have only default routing on RouteConfig file in development machine and keep getting 404, it seems that your problem comes from project's virtual path settings.

http://forums.asp.net/t/1893154.aspx?The+resource+cannot+be+found+404

If application is deployed on local host (or you have set Use local IIS Web Server) then it means you have created a virtual directory named "YourSite".

Right click your app project on VS, choose Properties, then go to "Web" part and set your site's virtual path on "Project Url".

For virtual directory problem on live IIS server, see here to add virtual directory into destination machine before deploying your app.

In addition, if you have custom routing rule, make sure the custom route placed properly on top of default routing rule.

The problem was that I had two Config Rules pointing to the same address. One of the other rules was pointing to the wrong controller. The wrong controller was erroring because I had set up the action, I had used the name of the controller as the action, thats a no-no. The above rule was correct but the incorrect rule was

 routes.MapRoute(
            name: "pagelist",
            url: "pagelist",
            defaults: new { controller = "pagelist", action = "pagelist", id = UrlParameter.Optional }
            );

the action should have been Index.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM