黑马程序员技术交流社区

标题: 把“~/test.aspx”转成"http://localhost:8088/test/test.aspx"的方法 [打印本页]

作者: 汪磊    时间: 2012-12-9 20:25
标题: 把“~/test.aspx”转成"http://localhost:8088/test/test.aspx"的方法
  1. /// <summary>
  2. /// 把~/test.aspx转化成http://localhost:8088/ModuleTest/test.aspx
  3. /// </summary>  
  4. /// <param name="path">如:~/test.aspx</param>  
  5. /// <returns></returns>  
  6. public static string GetVirsualURL(string path)  
  7. {  
  8.     path = path.Replace("~","");  
  9.     HttpRequest request = HttpContext.Current.Request;  
  10.     string port = request.Url.Port == 80 ? "" : ":" + request.Url.Port.ToString();  
  11.     if (request.ApplicationPath == "/")  
  12.     {  
  13.         return @"http://" + request.Url.Host + port+path;  
  14.     }  
  15.     else  
  16.     {  
  17.         return @"http://" + request.Url.Host + port + request.ApplicationPath+path;  
  18.     }  
  19. }  
复制代码

作者: 许庭洲    时间: 2012-12-9 20:30
值得学习ing!
作者: 杨占伟    时间: 2012-12-9 21:17
学习了~~~~




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2