+ -
当前位置:首页 → 问答吧 → 获取本页面名称如何写呀

获取本页面名称如何写呀

时间:2011-12-10

来源:互联网

protected void Page_Load(object sender, EventArgs e)
  {
  Response.Write(this.Page.Theme);
  }
我就想获取本页面的名称,但是以上这样子写,没有任何反映,该如何写代码呢

作者: zhengyingcan   发布时间: 2011-12-10

Response.Write(this.Page.Title);

作者: q107770540   发布时间: 2011-12-10

一样的没有,因为我没有设置Title属性, 我的意思是WEB名称是 login.aspx, 如何得到login这个名称呢

作者: zhengyingcan   发布时间: 2011-12-10

System.IO.Path.GetFileName(Request.PhysicalPath)

作者: orain   发布时间: 2011-12-10

如果不要扩展名 .aspx,可以这样:System.IO.Path.GetFileNameWithoutExtension(Request.PhysicalPath)

作者: orain   发布时间: 2011-12-10

引用 4 楼 orain 的回复:

如果不要扩展名 .aspx,可以这样:System.IO.Path.GetFileNameWithoutExtension(Request.PhysicalPath)


+1
附带解释:
Request.PhysicalPath-获取物理路径
System.IO.Path.GetFileNameWithoutExtension()-取得不带扩展名的文件名称

作者: heycoder   发布时间: 2011-12-12

Response.Write(System.IO.Path.GetFileName(Request.PhysicalPath).ToString());

作者: PoolBoys   发布时间: 2011-12-12

引用 5 楼 heycoder 的回复:

引用 4 楼 orain 的回复:

如果不要扩展名 .aspx,可以这样:System.IO.Path.GetFileNameWithoutExtension(Request.PhysicalPath)


+1
附带解释:
Request.PhysicalPath-获取物理路径
System.IO.Path.GetFileNameWithoutExtension()-取得不带……

非常的正解呀

作者: zhengyingcan   发布时间: 2011-12-12

那结贴吧

作者: zhanglong_longlong   发布时间: 2011-12-12

假设当前页完整地址是:http://www.test.com/aaa/bbb.aspx?id=5&name=kelli

"http://"是协议名

"www.test.com"是域名

"aaa"是站点名

"bbb.aspx"是页面名(文件名)

"id=5&name=kelli"是参数

【0】来源URL

string url=Request.UrlReferrer.ToString();

【1】获取 完整url (协议名+域名+站点名+文件名+参数)支持带端口

string url=Request.Url.ToString();

url= http://www.test.com/aaa/bbb.aspx?id=5&name=kelli

【2】获取 站点名+页面名+参数:

string url=Request.RawUrl;

(或 string url=Request.Url.PathAndQuery;)

url= /aaa/bbb.aspx?id=5&name=kelli

【3】获取 站点名+页面名:

string url=HttpContext.Current.Request.Url.AbsolutePath;

(或 string url= HttpContext.Current.Request.Path;)

url= aaa/bbb.aspx

【4】获取 域名:

string url=HttpContext.Current.Request.Url.Host;

url= www.test.com

【5】获取 参数:

string url= HttpContext.Current.Request.Url.Query;

url= ?id=5&name=kelli

作者: gzpepco   发布时间: 2011-12-12