Asp.net obtains the website address (not the requested address)

Source: Internet
Author: User

This. Request. url. getleftpart (uripartial. Authority)


You can get a http://www.baidu.com, no matter what the request is. In additionUripartial enumerated value. You can obtain strings such as path and querystring.


The following content source:Http://www.xueit.com/html/2009-03/21_932_00.html

---------------------------------------------------------------------

Obtain the URL of the website root directorySource code

Public static string getrooturi ()
{< BR style = "padding: 0px; margin: 0px;"> string apppath = "";
httpcontext httpcurrent = httpcontext. current;
httprequest req;
If (httpcurrent! = NULL)
{< BR style = "padding: 0px; margin: 0px;"> Req = httpcurrent. request;

String urlauthority = Req. url. getleftpart (uripartial. authority );
If (req. applicationpath = NULL | Req. applicationpath = "/")
// Directly install on the Web Site
Apppath = urlauthority;
Else
// Install it in a virtual subdirectory
Apppath = urlauthority + Req. applicationpath;
}
Return apppath;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.