简体   繁体   English

ASP.NET MVC 3,IIS7,404错误,无法正确路由?

[英]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. 我是ASP.NET MVC 3的新手,很抱歉,如果我的细节有些模糊不清。 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. 我正在运行IIS 7,设置为集成,我可以很好地访问应用程序的主页。 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." 主页的URL: http:// localhost / CMS / - 这将带您进入第一个屏幕,其中包含指向“合同”,“客户”和“员工”的链接。 Clicking one of those brings you to... 点击其中一个就会带你到...

http://localhost/CMS/Contract (or whichever you choose.) From there, it's broken down into different categories. http:// localhost / CMS / Contract (或您选择的任何一个。)从那里,它被分解为不同的类别。 One of them is "Create Contract." 其中一个是“创建合同”。 Here's the problem I'm having: that URL points to 这是我遇到的问题:该URL指向

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. http:// localhost / Contract / Create - 完全省略CMS部分并抛出404.我可以通过将CMS插回内部来实现它,并且这些页面正确路由。

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 听起来你不需要额外的路线,但需要使用HtmlHelper创建ActionLinks

When you are using your paths to to the controller actions you need to use @Url.Action("action", "controller"); 当您使用路径到控制器操作时,您需要使用@Url.Action("action", "controller"); instead of just using "action\\controller" . 而不是只使用"action\\controller" See an example http://codetuner.blogspot.com/2011/07/jquery-post-url-problems-in-iis-hosted.html 查看示例http://codetuner.blogspot.com/2011/07/jquery-post-url-problems-in-iis-hosted.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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