请问ASP.NET中怎么获取服务器地址
例如:当前页面为http://127.0.0.1/XX.aspx  则返回http://127.0.0.1/
     并且  如果为虚拟目录http://127.0.0.1/YY/下的网站  则返回http://127.0.0.1/YY/
C#解决~~~~~~~

解决方案 »

  1.   

    用 System.Security.Policy.Url 吗?  但是偶不会
      

  2.   

    一个很原始的方法:response.write("http://" & Request.ServerVariables("SERVER_NAME") & ":" & Request.ServerVariables("SERVER_PORT") & "/")显示的就是服务器的完整地址:)
      

  3.   

    既然知道了网址
    那么就可以直接将网址进行分析获取
    string str = "http://127.0.0.1/xx.asp";
    这个网址就要靠uri来获取了
    str = str.SubString(0,str.LastIndexOf("/")+1);
    好像是这样的
      

  4.   

    Dim ServerInfo As System.Environment
            'Dim url As String = Request.Url ' 获取有关当前请求的 URL 的信息。
            'Dim urlReferrer As String = Request.UrlReferrer '获取有关客户端上次请求的 URL 的信息,该请求链接到当前的 URL。
            Dim useragent As String = Request.UserAgent '获取客户端浏览器的原始用户代理信息。 
            Dim userhostaddress As String = Request.UserHostAddress '获取远程客户端的 IP 主机地址。
            Dim userhostname As String = Request.UserHostName '获取远程客户端的 DNS 名称。 
            'Dim userlanguages As String = Request.UserLanguages
            Dim platform As String = Request.Browser.Platform Label1.Text = "系统版本:" & ServerInfo.OSVersion.ToString
                Label6.Text = "系统目录:" & ServerInfo.SystemDirectory
                Label2.Text = "用户名称:" & ServerInfo.UserName
                Label3.Text = "计算机名:" & ServerInfo.MachineName
                Label4.Text = "浏览器版本:" & Request.Browser.Type
                Label5.Text = "COOKIES状态:" & Request.Browser.Cookies
                Label7.Text = "浏览器代理信息:" & useragent
                Label8.Text = "您的IP地址:" & userhostaddress
                Label9.Text = "DNS名称:" & userhostname
                Label10.Text = "系统平台:" & platform
      

  5.   

    System.Environment ServerInfo; 
    string useragent = Request.UserAgent; 
    string userhostaddress = Request.UserHostAddress; 
    string userhostname = Request.UserHostName; 
    string platform = Request.Browser.Platform; 
    Label1.Text = "系统版本:" + ServerInfo.OSVersion.ToString; 
    Label6.Text = "系统目录:" + ServerInfo.SystemDirectory; 
    Label2.Text = "用户名称:" + ServerInfo.UserName; 
    Label3.Text = "计算机名:" + ServerInfo.MachineName; 
    Label4.Text = "浏览器版本:" + Request.Browser.Type; 
    Label5.Text = "COOKIES状态:" + Request.Browser.Cookies; 
    Label7.Text = "浏览器代理信息:" + useragent; 
    Label8.Text = "您的IP地址:" + userhostaddress; 
    Label9.Text = "DNS名称:" + userhostname; 
    Label10.Text = "系统平台:" + platform;
      

  6.   

    没有直接满足楼主要求的变量,得拼一下字符串
    "http://" + Request.ServerVariables["HTTP_HOST"] + Request.ApplicationPath