如果一个本地地址:http://localhost:51771/ADMIN/Mobile_Web/index.aspx
部署到服务器上就变成了这个地址:http://demo.nowwin.cn/mobile_web/index.aspx。那么该如何动态获取呢。
我们可以找出规律,不管前面的地址是什么,文件目录都在mobile_web/目录下。则可以按照下面这种方式
int index = Request.Url.ToString().IndexOf("://");
index = Request.Url.ToString().IndexOf("/", index + 3);
index = Request.Url.ToString().IndexOf("/", index + 1);
//index = Request.Url.ToString().IndexOf("/", index + 1);//看你目录的层次了
string ff = Request.Url.ToString().Substring(0, index);
string url = ff + "/index.aspx";
希望大家给出更好的方法!