views:

192

answers:

3

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?

A: 

I'm not sure what you mean by "hidden portion" but have you tried ...

Request.Url.ToString()
JP Alioto
A: 

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"

Jordan S. Jones
that didnt work either :( it returns ~/, and when checking for File.Exists, it returns false! is there an IIS setting im missing?
Ayyash
Am I understanding this correctly, what you want is the ability to get the Physical File Path for the requested file? Where the Requested URL could be something like "http://mydomain.com/" and you would expect the result to be "~/default.aspx"?
Jordan S. Jones
+1  A: 

I don't think this is at all possible, so I relied on IIS7.0 rewrite feature to force the default.aspx to appear at all times..

Ayyash