读书人

怎么获得当前正在浏览的页面的相对路径

发布时间: 2012-01-05 22:36:54 作者: rapoo

如何获得当前正在浏览的页面的相对路径?即在服务器的路径?
如何获得当前正在浏览的页面的相对路径?即在服务器的路径?

我是要获得这个路径然后做为select的条件找到对应的导航栏菜单名字。
主要是想实现aspx页面上一个label能动态改变显示当前浏览的导航栏菜单名字。

[解决办法]
Response.Write(Request.ServerVariables[ "HTTP_REFERER "]);
[解决办法]
其实你可以用一个Session 传值吧?
[解决办法]
Request.Url.ToString()
[解决办法]
通过设计页面的trace=true可以看到相关的键值
把你想要的读出来就是了Response.Write(Request.ServerVariables[ "键名称 "]);
[解决办法]
server.Mappath()
[解决办法]
Request.Path

这个是获得当前页虚拟路径。
[解决办法]
Request.Path
[解决办法]
Request.Path
[解决办法]
Request.CurrentExecutionFilePath
[解决办法]
Request.Path好像不是楼主想要的
[解决办法]
Request.CurrentExecutionFilePath 不行吗?
比如我正在访问 index.aspx 这个会得到 http://yourwebsite/index.aspx
[解决办法]
Server.MapPath( "~/ ")
[解决办法]
得到http://yourwebsite/index.aspx后字符串截取。

[解决办法]
HttpContext.Current.Request.Url.Segments(HttpContext.Current.Request.Url.Segments.Length - 1);

获取当前URI的数组
[解决办法]
string aaa=Request.CurrentExecutionFilePath.ToString();

aaa=aaa.Substring(aaa.LastIndexOf( "/ ")+1);
[解决办法]
string str=Request.PathInfo;
str=str.Substring(str.LastIndexOf( "/ ")+1);
Response.Write(str);
[解决办法]
Request.Path
[解决办法]
Server.MapPath( "~/ ")

当然也可以用字符串进行转化
[解决办法]
看了以上朋友的方法
进行了总结
下面是代码
this.TextBox1.Text=this.Request.Url.ToString();
this.TextBox1.Text+= "\n "+this.Server.MapPath( "0 ");
this.TextBox1.Text+= "\n "+this.Server.MapPath( "~/ ");
this.TextBox1.Text+= "\n "+this.Request.Path.ToString();
this.TextBox1.Text+= "\n "+this.Request.CurrentExecutionFilePath.ToString();


对应的结果如下:

http://localhost/00002/NewFolder1/WebForm1.aspx
c:\inetpub\wwwroot\00002\NewFolder1\0
c:\inetpub\wwwroot\00002\
/00002/NewFolder1/WebForm1.aspx
/00002/NewFolder1/WebForm1.aspx

供搂住参考吧
[解决办法]
如:
http://localhost/test/default.aspx?fd=154&fds=24

Request( "URL ").ToString()



得到的果是:test/default.aspx
行?
[解决办法]
private string GetBaseURL()//这个函数可以得到http://localhost/
{
if (HttpContext.Current.Request.ApplicationPath == "/ ")
{
return @ "http:// " + HttpContext.Current.Request.Url.Host;
}
else
{
return @ "http:// " + HttpContext.Current.Request.Url.Host + HttpContext.Current.Request.ApplicationPath;
}
}
再跟Request.CurrentExecutionFilePath的结果运算一下,简单得很啊。
[解决办法]
Response.Write(Request.ServerVariables[ "HTTP_REFERER "]);
--------------------
如果浏览器不传递Referer,这个方法得到的是null值,即Request.UrlReferrer=null,这样是不行的。

用Request.Path就得到当前url相对路径了。

读书人网 >asp.net

热点推荐