获取虚拟路径

~/VisitorView.aspx 转成http://localhost:15982/Synair.New.Visitor/VisitorView.aspx

         public static string GetVirsualURL(string path)

        {

            path = path.Replace("~", "");

            HttpRequest request = HttpContext.Current.Request;

            string port = request.Url.Port == 80 ? "" : ":" + request.Url.Port.ToString();

            if (request.ApplicationPath == "/")

            {

                return @"http://" + request.Url.Host + port + path;

            }

            else

            {

                return @"http://" + request.Url.Host + port + request.ApplicationPath + path;

            }

        }

posted @ 2009-10-15 08:26  小巩  阅读(105)  评论(0)    收藏  举报