3

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?

2 Answers 2

2

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

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

Comments

2

You can check Request.Headers["Host"] to find the current hostname.

You may want to strip out the www., if present.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.