简体   繁体   English

检索网址的隐藏default.aspx段

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

I tried to display the url using all sorts of methods of HttpRequest, I tried VirtualPathUtility object as well, but I never was able to display the hidden portion "default.aspx" of the default... what is the method or property that retrieves this segment of the url? 我尝试使用HttpRequest的各种方法来显示url,也尝试了VirtualPathUtility对象,但是我无法显示默认值的隐藏部分“ default.aspx” ...检索的方法或属性是什么?这部分网址?

reason being, I am so close to creating a 404 on application level that catches all 404s, even html pages, by using File.Exist() on the mapped path of the url, unfortunately, that does not work on the default page. 原因是,我非常接近在应用程序级别上创建404,以通过在URL的映射路径上使用File.Exist()来捕获所有404,甚至是html页面,不幸的是,这在默认页面上不起作用。

I have seen few articles trying to do the opposite, remove default.aspx when it occurs, this is not the case here. 我见过几篇文章试图做相反的事情,当default.aspx出现时,将其删除,这不是这种情况。

Edit: here is what I am trying: 编辑:这是我正在尝试:

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");

now you see, if the page is localhost/lexus/default.aspx , it works fine with no errors, but if I type in the address http://localhost/lexus/ , the error is thrown, because if you try to output the fullOriginalPath, it does not have "default.aspx" part of it, so Exists returns false! 现在,您看到的是,如果页面是localhost / lexus / default.aspx ,则可以正常运行而没有错误,但是如果我输入地址http:// localhost / lexus / ,则会引发错误,因为如果您尝试输出fullOriginalPath,它没有“ default.aspx”部分,因此Exists返回false! do you have a better way of checking for validity of physical files? 您是否有更好的方法来检查物理文件的有效性?

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

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

Request.Url.ToString()

Ye be looking for the AppRelativeCurrentExecutionFilePath Property on the HttpRequest object: http://msdn.microsoft.com/en-us/library/system.web.httprequest.apprelativecurrentexecutionfilepath.aspx 您正在HttpRequest对象上寻找AppRelativeCurrentExecutionFilePath属性: http : //msdn.microsoft.com/zh-cn/library/system.web.httprequest.apprelativecurrentexecutionfilepath.aspx

If someone makes a request to http://yourdomain.com/ the value of AppRelativeCurrentExecutionFilePath would be "~/default.aspx" 如果有人向http://yourdomain.com/发出请求,则AppRelativeCurrentExecutionFilePath的值将为"~/default.aspx"

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

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