简体   繁体   中英

ASP.NET MVC 3, IIS7, 404 Error, not routing correctly?

I'm newish to ASP.NET MVC 3, so sorry if I'm my details are slightly murky. I'm trying to publish my web app to a server here. I'm running in IIS 7, set to integrated, and I can get to the home page of the app just fine. However, certain links remove the directory out of the url. Example:

URL of home page: http://localhost/CMS/ - this will take you to the first screen, with links to "Contract," "Customer," and "Employee." Clicking one of those brings you to...

http://localhost/CMS/Contract (or whichever you choose.) From there, it's broken down into different categories. One of them is "Create Contract." Here's the problem I'm having: that URL points to

http://localhost/Contract/Create - completely omitting the CMS part out and throwing a 404. I can reach it by inserting CMS back inside, and those pages route correctly.

What could be wrong? Let me know if you need more information on any of my code or whatever.

You can define an alternate controller in the route than what you would expect

routes.MapRoute("Contract", "Contract/{action}",
    new { controller = "cms", action = "index" }
);

and you should be constructing your links like this within your pages

<%=Html.ActionLink("Contract", "create", "cms") %>

rather than doing it the old fashioned way like

<a href="<%=ResolveUrl("~/Contracts/Create") %>">Contracts</a>

which side steps routing.


It sounds like you don't need additional routes but need to create ActionLinks propery using the HtmlHelper

When you are using your paths to to the controller actions you need to use @Url.Action("action", "controller"); instead of just using "action\\controller" . See an example http://codetuner.blogspot.com/2011/07/jquery-post-url-problems-in-iis-hosted.html

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