取得当前的文件之前的URL地址.

建议写在Global.asax 的函数Session_Start内

void Session_Start(object sender, EventArgs e)
{
// 在新会话启动时运行的代码
string Path = string.Empty;
string pre = Request.ServerVariables["http_host"].ToString().Trim();
string pos = Request.ServerVariables["path_info"].ToString().Trim();
int i;
i = pre.IndexOf("localhost:");
if (i < 0) { Path = pre + "/"; }
else { Path = pre + pos.Substring(0, pos.LastIndexOf("/") + 1); }
Session["Path"] = "http://" + Path;

}

你可能感兴趣的:(url)