博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
get the page name from url
阅读量:4618 次
发布时间:2019-06-09

本文共 1028 字,大约阅读时间需要 3 分钟。

The way I interpret the question what you're looking for is an efficient way of retrieving the name of the currently executing aspx page, ie System.Web.UI.Page.

If that is true you shouldn't have to deal with any FileInfo objects or hit the filesytem. Simply use the on the page object.

using System; using System.IO; using System.Web.UI; namespace WebApplication1 { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string pageName = Path.GetFileNameWithoutExtension(Page.AppRelativeVirtualPath); } } }

If you wan't to get the fully qualified (or "rooted") path of your currently executing page you can use like this

string path = Server.MapPath(Page.AppRelativeVirtualPath); //这里的路径是网页对应的物理文件的路径

Using AppRelativeVirtualPath has the benefit of working even when you're using url rewriting and since it doesn't use Request.Url (which is provided by your users) you don't have to worry about potentially malicious data.

 

转载于:https://www.cnblogs.com/chucklu/p/9707290.html

你可能感兴趣的文章
LeetCode 813. Largest Sum of Averages
查看>>
JCEF-鼠标右键菜单
查看>>
const关键字总结
查看>>
Qt--多线程间的互斥
查看>>
httpContext.User.Identity.IsAuthenticated 总是为fasle
查看>>
Docker踩坑小记
查看>>
AutoResetEvent控制线程用法
查看>>
怎么把控制台输入命令之后显示的东西保存到一个记事本中
查看>>
使用shutdown命令实现局域网内远程关机、重启整蛊他人
查看>>
Struts 笔记 内部资料 请勿转载 谢谢合作
查看>>
去面试吧!CSS
查看>>
hdu 1045
查看>>
使用时间戳和sequence生成主键的function
查看>>
用字体开透明窟窿
查看>>
淡入淡出的效果
查看>>
Python加密与解密
查看>>
C++在Ubuntu上编译mysql问题
查看>>
Java学习--Cookie 和session
查看>>
rem布局在webview中页面错乱
查看>>
第12章:MongoDB-CRUD操作--文档--查询--游标详解
查看>>