leora
leora

Reputation: 196439

in asp.net-mvc, how can i build up URLs in controller

if my current controller, my URL is:

 http://test.mysite.com/Person/Detail/1

how can i extract into a variable:

  1. Full URL (http://test.mysite.com/Person/Detail/1)
  2. Root url (http://test.mysite.com)

i am sending links inside of emails so i can't just use relative URLs (that why i need something that will get me these URLs

Upvotes: 0

Views: 134

Answers (2)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

  1. var fullUrl = Request.RawUrl;.
  2. var rootUrl = Request.Url.GetLeftPart(UriPartial.Authority);

Upvotes: 3

Andrew
Andrew

Reputation: 10033

Have a look at this answer it may be of use:

How can I return the current action in an ASP.NET MVC view?

The Uri object is useful when working with URLs also

Upvotes: 0

Related Questions