开发者

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 pag开发者_运维知识库e 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜