开发者

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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜