简体   繁体   中英

HttpContext.Current.Request.Url.Host return incorrect value

My web url is www.test.com and I try to get this URL by HttpContext.Current.Request.Url.Host but it return IP Address instead of that URL. I check by fiddler and it Host is also IP Address. I want to know how to fix this?

Use below to fetch url from code:

string url = HttpContext.Current.Request.Url.ToString().Trim(); 

You are getting the IP since you are trying to use the Host property of the URL . You should see the AbsoluteUri property of URL to get complete URL Info. eg

String url = HttpContext.Current.Request.Url.AbsoluteUri;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM