例如www.163.com
    user.bolg.163.com
  
  用URI可以根据URL得到上述HOST,但我只要域名部分。即上述要求返回163.com如何得到?

解决方案 »

  1.   

    string mystring = "user.bolg.163.com";
    int i = mystring.LastIndexOf('.', (mystring.LastIndexOf(".") - 1));
    Response.Write(mystring.Substring(i+1));ystring = "bolg.163.com";
    i = mystring.LastIndexOf('.', (mystring.LastIndexOf(".") - 1));
    Response.Write(mystring.Substring(i+1));
      

  2.   

    HttpContext.Current.Request.UrlRequest.ServerVariables["HTTP_HOST"] + Request.ServerVariables["SCRIPT_NAME"]
    Request.ApplicationPath: /testweb
    Request.CurrentExecutionFilePath: /testweb/default.aspx
    Request.FilePath: /testweb/default.aspx
    Request.Path: /testweb/default.aspx
    Request.PathInfo:
    Request.PhysicalApplicationPath: E:\WWW\testweb\
    Request.PhysicalPath: E:\WWW\testweb\default.aspx
    Request.RawUrl: /testweb/default.aspx
    Request.Url.AbsolutePath: /testweb/default.aspx
    Request.Url.AbsoluteUri: http://www.test.com/testweb/default.aspx
    Request.Url.Host: www.test.com
    Request.Url.LocalPath: /testweb/default.aspx
      

  3.   

    刚忘记写了string mystring = Request.ServerVariables["HTTP_HOST"].ToString(); 
    int i = mystring.LastIndexOf('.', (mystring.LastIndexOf(".") - 1)); 
    Response.Write(mystring.Substring(i+1)); 
      

  4.   

     Request.Url.Host.ToString().Replace("wwww.","")
      

  5.   

    http://topic.csdn.net/u/20091108/11/93fa8e97-3e24-4768-b68d-6884a89ac13f.html