ASP.NET MVC generate subdomain URL in View - asp.net-mvc

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?

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

You can check Request.Headers["Host"] to find the current hostname.
You may want to strip out the www., if present.

Related

how can I localize mvc routes?

I am currently working with localizing my MVC4 web application and have run in to an issue. My site is in four languages, English, French, Russian and Polish. I set up the sites culture based upon what the user selects. This is not tracked in the url.
I want my urls to be SEO friendly. So I need them to be localized. The tricky part though is that fact I routes set up for my controllers in English. For example
/product/product-name is mapped to the product controller and the get action
/customer/details is mapped to the customer controller and the details action
How can I localize the routes to different languages/cultures? So when I create an action link it maps to correct controller/action, generating the localized url?
I found this solution and it is very elegant but the issue I have is that it does not work as well for dynamic url's, as there is a need for explicit mapping.
Actually I don't know the right answer for that question and it's really very interesting how it possible to do that with standard MVC routing.
But if you do not find proper way to implement that with standard options you could implementing that by hands with the helps of front controler.
You create the class which will be main point of availability inside your app. And inside that method you could implement redirecting logic which will redirect you to the proper controller/action.

ASP.NET MVC getting calling URL

In an ASP.NET MVC 4 application, I would like to get the URL of the site calling the application. That is, I would like to be able to change the web site slightly depending upon which URL it is called from, and as such need to know how to tell what the calling URL is? I would then call a different index.cshtml file depending on which site it is called from.
Any help would be appreciated
I'm not completely sure what you want to do, but would this do the trick for you:
Request.UrlReferrer
Or
Request.ServerVariables["HTTP_Referer"]
Although I'd prefer the first one.

ASP.NET MVC - What is the benefit of using Url.RouteUrl or Url.Action versus just using the URL directly?

What is the benefit of using Url.RouteUrl or Url.Action versus just using the URL directly?
If you change your routing configuration, by using Url.RouteUrl or Url.Action your generated Url's will update along with your routing configuration.
I find the real benefit comes when tied together with T4MVC. Then I have strongly typed access to my Action routes, so if my controller's change the compiler alerts me if any of my Url's need to change as well.
It's very simple to set up custom routing rules to create so-called "pretty" (or SEO-friendly) URLs. If you ever change one of those URLs, you don't want to have to go through your entire application and change it every time you link to that action. On the other hand, if you use Url.Action, it will change automatically.

Geeky urls to Search Engine Friendly urls in IIS without sacrificing incoming links

I have a website where my present "geeky" urls look like:
http://www.bestatdubaiholidays.co.uk/pages/Quote/Details.aspx?GUID=01a25b0c-e0ac-40ba-abd1-298f3abd9612
I want to change these to Search Engine Friendly ones - something like:
http://www.bestatdubaiholidays.co.uk/the-palm-atlantis.aspx
or
http://www.bestatdubaiholidays.co.uk/the-palm-atlantis
I have hundreds of incoming links (from ad campaigns and other sites) to my geeky urls that I want to retain.
So if someone types a geeky url, I want the address bar to show the equivalent search engine friendly url.
Can anyone help? Referring to other articles won't help. Believe me, I've read every one of them. Any example urls will be helpful.
Use something like this http://blog.eworldui.net/post/2008/04/ASPNET-MVC---Legacy-Url-Routing.aspx
You don't have to use MVC, the routing classes are standalone now
I suggest using a Front controller. This means that you use the rewrite engine of whatever httpd server you're using to redirect ALL requests to a single file (index.php or index.aspx or whathaveyou) and then you use code in that file to dispatch to the appropriate page. You can do a redirect from the geeky URLs to the friendly URLs, and if it's a friendly url then you load the appropriate page.
This would be way easier than writing huge rewrite rules for each type of page you might have. And this way all of the work is done in the same language your site is already running, so you don't have to learn and maintain a new file that is in its own language just for the redirection.

ASP.net MVC HomeController URL

By default the MVC Preview 5 web project comes with a HomeController.vb class. This sets the web URL to http://www.mywebsite.com/home/ by default. If I just wanted this to be http://www.mywebsite.com/ by default, how would I accomplish that?
Answered already so I'm just going to direct you to How do I get rid of Home in ASP.Net MVC?.
Users with 10k+ rep can also refer to https://stackoverflow.com/questions/33861/aspnet-mvc-routing-basics-root-route (deleted)
I'm not sure I understand your question, if what you want is to go to http://www.mywebsite.com/ and not have it be trailed by /home, that is the behavior you will get.
Is there something else you were looking for?

Resources