Reputation: 57479
How do I generate a subdomain URL in the view? For ex, My application is on www.lol.com
, which could change sometime in the near future. I want to link to email on google apps located on the subdomain mail.lol.com
.
How do I accomplish this so I dont have to hardcode an absolute URL?
Upvotes: 3
Views: 386
Reputation: 245499
ASP.NET MVC isn't going to handle this for you.
Luckily, you're not the first one to want to do something like this. Since you have full control over routing in .NET MVC, you just have to customize something for yourself.
If you want something simple that will take out the www and replace it with mail (or append mail if there is no www), then you can check out the Request.Headers["host"]
value and modify it as necessary.
If you actually want something flexible to handle the routing for you then you could check out this post on how to get started:
Hanssens.org | ASP.NET MVC Subdomain Routing
Upvotes: 2
Reputation: 888213
You can check Request.Headers["Host"]
to find the current hostname.
You may want to strip out the www.
, if present.
Upvotes: 2