Last post Jan 29, 2007 10:41 AM by craigw7272
Jan 24, 2007 11:35 AM|nathanaeljones|LINK
This one has me stumped. I’ve spent 7 hours today with Reflector, pouring over the System.Web source code. MSDN doesn’t seem too helpful when it comes to ASP.NET, either.
I am using IIS 5.1 and ASP.NET 2.0.
I have set the IIS 404 URL to an .aspx page, in an attempt to direct all requests for non-existent resources to the runtime.
This has two benefits: I can log requests for image/css files to a 'broken references' log, and I can perform URL rewriting.
I have an error logging system that can roll-up multiple similar errors or events, so being able to log misspelled filenames would be a major feature, and would eliminate a serious pain-point.
Unfortunately, IIS performs some URL rewriting of its own; the runtime receives a request for the configured url (/iis404.aspx).
Thus, the runtime resolves all image/css/link paths relative to the root, where iis404.aspx is located, instead of to the actual path the browser requested (/user/testaspx).
IIS passes on the original url like this:
It seems to me like I would need to modify the context of the current request in some way to account for the difference.
I've tried running this code from the AuthorizeRequest and OnError sections, but I can't get an HttpHandler to process the HttpRequest object I create.
//Where iispath is
//Where querystringpart is “”
//Where current.local is “C:\\Inet…\user\testaspx”
HttpRequest hr = new HttpRequest(current.Local, iispath, querystringpart);
HttpContext hc = new HttpContext(hr, Response);
//Doesn't work... HttpContext.Current is null
Any tips or pointers are appreciated!
What is the ideal way to reference stylesheets so that they appear correctly both in the designer, and from different url folder levels in production? I have found at least 4^2^2 incorrect ways of doing this.
What do you use for URL and path manipulation? I know the runtime uses System.Web.VirtualPath and System.Web.Util.UrlPath, but they are marked ‘internal’. I’ve had to create my own class to maintain URL-parsing consistency.
Is there a reason why ASP.NET uses redirection instead of URL rewriting for error pages? I personally find it much easier to deal with errors and 404s if the URL doesn’t change on me. I hate it when I misspell one character, and the server
redirects me to a new URL, denying me the chance to rectify my mistake. I have implemented a custom system in global.asax that uses Server.Transfer to handle error messages; the admin is given a page with descriptive exception details, while all the other
unauthenticated users are provided with a generic message. Is this an acceptable approach?
Is it fine to ignore the url authorization system and simply use User.IsInRole throughout my code? Many of my pages do not have very clear-cut security requirements, and must perform complex role checks.
Jan 29, 2007 10:41 AM|craigw7272|LINK
You can try this;
In your global.asax put code in the Application_Error event which does fire for missing files and then do your logging etc. That works for me.
For your other questions: For CSS use themes.