views:

432

answers:

4

Hi All,

I have an asp.net MVC App that I want to deploy to IIS 5 and/or 6 using a Virtual Directory.

I have already performed the wildcard routing, but I have a problem with relative paths.

Imagine I have created a virtual directory called myApp.

After deploying I can go to http://localhost/myApp and am greeted by the index page. My index page has a link defined as <a href="/Employees">Employees</a>. Clicking on this navigates to http://localhost/Employees which results in a 404 error.

I would like it to navigate to http://localhost/myApp/Employees instead, but I would prefer it if I didn't have to code the virtual directory name into my project.

Thanks in advance for any help.

+2  A: 

Use Html.ActionLink to generate your hyperlinks rather than creating them directly, I think that'll sort it for you. Alternatively, use ./Employees which should get you where you want to go.

Lazarus
thanks, this did the trick!
jheppinstall
A: 

Don't use an absolute reference: instead of '/Employees', just use 'Employees' without the /.

Vinay Sajip
+1  A: 

Use Url.Content

<a href="<%= Url.Content("~/Employees") %>">Employees</a>
eu-ge-ne
A: 

Url rewriting can help you to solve the problem. I've implemented solution allowing to deploy MVC application at any IIS version even when virtual hosting is used. http://www.codeproject.com/KB/aspnet/iis-aspnet-url-rewriting.aspx

Alex Ilyin