I am using ASP.NET MVC4 with WinHost.
Just like the question asked here, I ran into the same issue:
I'm trying out WinHost and I'm running into some issues with sub-domains. On WinHost, you can have multiple sub-domains per hosting account, but each sub-domain points to the root website. E.g. you can have www.example.com, sub1.example.com, and sub2.example.com but all of them display the content at http://www.example.com/.
Other Hosts allow you to point sub-domains to a sub folder in your website. This would allow you to point sub1.example.com to /sub1, sub2.example.com to /sub2 and www.example.com to /.
WinHost recommends using an asp/aspx page to redirect http://sub1.example.com to http://sub1.example.com/sub1, which points to /sub1. While that would work, I'd like to not have the subdomain in the url twice.
So I tried using IIS7 URL Rewrite to point http://sub1.example.com to /sub1. Ben Powell describes this in detail on his blog.
I've managed to get this portion to work so that http://sub1.example.com actually points to my virtual application "/sub1" in IIS.
If I use Url.Content, it works flawlessly.
Now, I am using ASP.NET Optimization and I bundle scripts and css. Issue is that it absolutely require a relative url ie:
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*"));
However, because it's a relative url here is what I will get in the markup:
<script src="/sub1/bundles/jqueryval?v=UgyEMAYOuSB9Bb6HcOEVHpd6fIIp54yF086SRNVcdIY1"></script>
Of course, because of the "sub1" it doesn't find the file. I thought about URL Redirect that I never actually got to work. Maybe a route in MVC? Unsure how to do this as well. I could also drop the bundling alltogether to use "Url.Content" which I think is sad.
What would be the best way to handle this issue?