简体   繁体   中英

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?

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.

I have seen few articles trying to do the opposite, remove default.aspx when it occurs, this is not the case here.

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! 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

If someone makes a request to http://yourdomain.com/ the value of AppRelativeCurrentExecutionFilePath would be "~/default.aspx"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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