繁体   English   中英

检索网址的隐藏default.aspx段

[英]retrieve the hidden default.aspx segment of a url

我尝试使用HttpRequest的各种方法来显示url,也尝试了VirtualPathUtility对象,但是我无法显示默认值的隐藏部分“ default.aspx” ...检索的方法或属性是什么?这部分网址?

原因是,我非常接近在应用程序级别上创建404,以通过在URL的映射路径上使用File.Exist()来捕获所有404,甚至是html页面,不幸的是,这在默认页面上不起作用。

我见过几篇文章试图做相反的事情,当default.aspx出现时,将其删除,这不是这种情况。

编辑:这是我正在尝试:

string fullOrigionalpath = context.Request.CurrentExecutionFilePath.ToString();
bool newUrl = System.IO.File.Exists(context.Server.MapPath(fullOrigionalpath));
if (!newUrl) throw new HttpException(404,"page not found");

现在,您看到的是,如果页面是localhost / lexus / default.aspx ,则可以正常运行而没有错误,但是如果我输入地址http:// localhost / lexus / ,则会引发错误,因为如果您尝试输出fullOriginalPath,它没有“ default.aspx”部分,因此Exists返回false! 您是否有更好的方法来检查物理文件的有效性?

我认为这根本不可能,因此我依靠IIS7.0重写功能来强制default.aspx始终出现。

我不确定“隐藏部分”是什么意思,但是您尝试过...

Request.Url.ToString()

您正在HttpRequest对象上寻找AppRelativeCurrentExecutionFilePath属性: http : //msdn.microsoft.com/zh-cn/library/system.web.httprequest.apprelativecurrentexecutionfilepath.aspx

如果有人向http://yourdomain.com/发出请求,则AppRelativeCurrentExecutionFilePath的值将为"~/default.aspx"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM