小谈asp & asp.net取虚拟目录路径
asp:
url ="http://"&request.ServerVariables("HTTP_HOST")&"/xml/"
url_myspace = url&"guide.xml"
以后引用url_myspace就不必每次更改url了,直接通过
request.ServerVariables("HTTP_HOST")获得服务器路径,request.ServerVariables()中还有众多参数,在DW中可以用时具体查看。
asp.net:
也是使用request.ServerVariables(),具体如下:
string strServer = "http://" + Request.ServerVariables["SERVER_NAME"].ToString();
string strPort = ":" + Convert.ToString(Request.ServerVariables["SERVER_PORT"]);
string strRoot = Request.ApplicationPath + "/";
if (strPort.Trim() == ":80")
{
strPort = "";
}
string strUrl = strServer + strPort + strRoot;
对比了下好像后者还要单独取端口号,asp中可直接取得,asp.net的取端口加判断。

浙公网安备 33010602011771号