How can I trick MVC into rendering links based on a different virtual path?

I am running many applications at discountasp.net with a subdomain addon. Since I cannot have multiple IIS sites with shared hosting, I also wrote an HTTP module that allows sites in subfolders to act as if they were running in the root directory. So, for example, instead of posting my blog on dandoes.net/blog, I can post it on blog.dandoes.net (which really is dandoes.net). It works great so far when I try to use it along with MVC.

The HtmlHelper generates its URLs based on the application's virtual path, not the path data in the URL. So, if I'm on blog.dandoes.net and I want a link to blog.dandoes.net/Samples, I might have this code:

<%=Html.ActionLink("Samples", "Index", "Samples")%>

      

Under normal circumstances this will create the url blog.dandoes.net/Samples, but instead it generates the blog.dandoes.net/Blog/Samples file because the virtual directory is / Blog.

I could take 5 minutes and write something really hacky to do what I want, but I think it would be really interesting if I could get the MVC environment to do what I want.

So, is there a way to get it to display the correct urls?

+1


source to share


1 answer


The HTML helper is simply a class that returns a string to your code. All you have to do is write your own helper class to output the string in the format you want.



+1


source







All Articles