I have written an ASP.NET MVC3 Web application which runs perfectly inside the Visual Studio development web server and run on a specific IIS web server.
I have successfully published the same web application on another IIS web server. It runs well except for a strange behavior.
My controller actions returns the content without problem, but the layout page isn’t rendered. I end up having only the content returned by the controller action.
What am I missing ?
I bet you have hardcoded the urls to scripts and CSS in your view instead of using Url helpers. You wrote:
instead of the correct way:
or you wrote:
instead of the correct way:
Now go ahead and search for all places where you have hardcoded urls like this and replace them with urls generated by helpers.
The reason why your site doesn’t work when deployed in IIS is because in IIS there’s a probably a virtual directory that you have to take into account. So the correct address is
http://example.com/myappname/content/site.csswhereas when running locally there’s no such directoryhttp://localhost:1234/content/site.css.