Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the root Url

Tags:

asp.net-mvc

The code below is a dreadful hack.

Uri linkUri = HttpContext.Current.Request.Url;
string link = linkUri.ToString().Substring(0, linkUri.ToString().IndexOf("Users/Create"));

Instead of editing the string, how do I get the correct route Url in the first place?

For example I want to get http://localhost:9999/ instead of http://localhost:9999/Users/Create

like image 922
arame3333 Avatar asked Sep 10 '10 07:09

arame3333


People also ask

What does root URL mean?

A root URL is the start or index page of a domain on a web server. Colloquially, many users call the homepage the “root URL” as well.

What is Webroot PHP?

It is a particular folder on the web server but can be a different folder for different situations. For web pages visible on the web the root folder is the one that the domain name itself points to.


1 Answers

You could use the Content method of UrlHelper:

string root = urlHelper.Content("~/");
like image 120
Darin Dimitrov Avatar answered Sep 29 '22 08:09

Darin Dimitrov