https://stackoverflow.com/questions/1874532/better-way-to-get-page-name

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 AppRelativeVirtualPath property 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 Server.MapPath 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.

get the page name from url的更多相关文章

  1. 修正Thinkphp 3.2 分页Page类以支持URL路由

    http://www.thinkphp.cn/topic/22114.html 最终目的实现以http://www.fl900.com/product/lists/1-0-0-1.html这样的URL ...

  2. Dynamics 365 联系人Contact的快速创建窗体,如何知道父窗体是哪个实体,通过window.top.parent.Xrm.Page.getUrl()可以知道父窗体的URL

    Dynamics 365 联系人Contact的快速创建窗体,如何知道父窗体是哪个实体?相信有人会遇到过这种头疼的问题,我这里分享一种方式: 在contact快速创建窗体的onload时间执行如下代码 ...

  3. github page+jekyll搭博客初体验

    div.oembedall-githubrepos { border: 1px solid #DDD; list-style-type: none; margin: 0 0 10px; padding ...

  4. python 爬取乌云所有厂商名字,url,漏洞总数 并存入数据库

    需要:MySQLdb 下面是数据表结构: /* Navicat MySQL Data Transfer Source Server : 127.0.0.1 Source Server Version ...

  5. paip.uapi 获取网络url内容html 的方法java php ahk c++ python总结.

    paip.uapi 获取网络url内容html 的方法java php ahk c++ python总结. 各种语言总结比较,脚本php.python果然是方便.简短,实用. uapi : get_w ...

  6. 从Wep page到Application

    需要做一个选择,是Web app还是Native app,当然,还有第三种,Hybrid app. 现在手机用户越来越多,电脑终端浏览器也在不断的更新换代,推陈出新,网页已经不仅仅是用来分享信息这么简 ...

  7. Get URL parameters & values with jQuery

    原文: http://jquery-howto.blogspot.jp/2009/09/get-url-parameters-values-with-jquery.html In this post, ...

  8. C# 根据URL返回HTML_根据URL获取图片信息/缩略图

    /// <summary> /// 根据URL 返回HTML /// </summary> private List<string> GetHtmlByUrl(st ...

  9. Header() in PHP &html – Refresh (Redirect) to Location (URL) in X seconds

    Case 1 : Redirect a page to a URL without waiting in PHP. 1 header("Location: index.php"); ...

随机推荐

  1. 【02】koala编译中文出错(已放弃不用)

    http://koala-app.com/index-zh.html koala 下载地址.     sass.中文编译出错: 打开 Koala文件夹位置->rubygems->gems- ...

  2. NLS_LANG在客户端不能确定,字符集转变将造成不可预期的后果

    原因:1,没有客服端配置字符集2,客户端字符集跟服务端字符集不一致 解决:1,打开plsql 帮助-支持信息看看uls_lang是否设置 2,查看服务器端字符集 Select *from V$NLS_ ...

  3. 【Ajax 4】Ajax、JavaScript和JQuery的联系和区别

    导读:在之前,就分别学习了Ajax.JavaScript和JQuery,然后对于这三者之间的关系,是一直云里雾里的.尤其是后来学到了Ajax,就更是不明白了.现在,就给总结总结. 一.基本概述 1.1 ...

  4. vscode 打开新文件覆盖窗口,始终显示一个窗口

    一直在使用vscode 编辑器,里面的扩展用的比较舒服,但是最近遇到一个小问题,一直也没有找好的解决办法,今天无意中把问题给解决了.具体如下 之前使用编辑器,可以同时打开多个文件,而且是多窗口展示的, ...

  5. POJ3233:Matrix Power Series

    对n<=30(其实可以100)大小的矩阵A求A^1+A^2+……+A^K,K<=1e9,A中的数%m. 从K的二进制位入手.K分解二进制,比如10110,令F[i]=A^1+A^2+……+ ...

  6. Separate code and data contexts: an architectural approach to virtual text sharing

    The present invention provides a processor including a core unit for processing requests from at lea ...

  7. spring boot 没有主清单属性

  8. Swift--字典的了解

    字典存储时,key和value值的类型都是固定的,且都是无序的. 1.字典类型的缩写语法 在swift中,字典的完整格式如下: Dictionary<Key, Value> 注意:字典的k ...

  9. Match the string--hdu1797(模拟)

    http://acm.hdu.edu.cn/showproblem.php?pid=1797 就是模拟 我的思路是标记aba 和h的位置 然后就判断是否正确  就行了 还有就是  最后 fkfkfkf ...

  10. [转] Oracle数据库维护常用SQL语句集合

           原文地址 进程相关: 1. 求当前会话的SID,SERIAL# SELECT Sid, Serial# FROM V$session WHERE Audsid = Sys_Context ...