0

Hi I am deploying an MVC application on IIS on Win7. I have deployed it on localhost/appPortal. appPortal is configured as application rather than virtual directory. Unfortunately the application root in MVC gets mapped to localhost instead of localhost/appPortal. This is breaking all my links to scripts, css, images etc. Can anyone help me in understanding why this happens and how to fix it?

3 Answers 3

2

More information would be interesting on how you are creating the links.

The first thing to check is that the application is correctly created in IIS, which I suppose it is. (If not you'll probably get errors from nested web.config files)

The second thing, urls should be created like this and not directly:

<%= Url.Content("~/yourpath/yourfile.css") %>

Maybe this question about Url.Content shows you more options. Check as well MSDN documentation on UrlHelper and HtmlHelper.

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

2 Comments

Actually the application is developed by some other team who is hosting it on their IIS root. All the references to assets are using relative paths as picked up by VS2008 during development. The application meaning the views render properly but scripts, CSS do not work. Do I need to change ref. to all static content like your solution?
The problem is that JS is not vdir aware. Our solution right now is creating a JS object in a script called from the master that has a property with the value of the current vdir path, i.e.: Globals.rootPath = "/vdir/" or "/" if it's a subdomain. For referencing CSS and scripts we use Url.Content.
0

The best solution is not to use rooted links in your application (ones which start with /). You can use ~/ as a reference to the root of the application. I use things like this

<script src="<%=ResolveClientUrl("~/script/something.js") %>"

to resolve to /scripts. Doing this makes your application more portable.

Comments

0

You could also just use the HTML 5 doc type and the <base> tag.

Yep, I just did that.

Thats probably not an option though so you should use the URL helper as Marc stated.

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.