0

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.

1
  • Are Contract, Customer, and Employee controllers, respectively? Commented Jul 28, 2011 at 15:15

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

3 Comments

I'll try this and get back to you. I am already using ActionLink for everything. Thanks :)
What confuses me is that when I debug it locally, it works completely fine. It's publishing that's 404'ing it.
Idiot me didn't realize that some of the links actually were NOT ActionLinked. This fixed it. Much thanks. :)
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.