views:

128

answers:

1

The following line:

string url = HttpContext.Current.Request.Url.AbsolutePath.ToLower();

results in an unauthorizedaccess exception.

This is odd to me, especially since I can hover over the variable and see its value.

This is inside a custom class inherited from IHttpModule that runs as aspx are loaded. I'm using this to get the user requesting the page and the page being requested. The line of code above is intended to detect which page is being requested.

Any ideas? This seems very weird to me.

+1  A: 

Is it possible that you have selected Release mode instead of Debug mode for compilation. Even when debugging, in Release mode it's possible that the line reported for the exception is different than the line actually causing the exception due to optimizations.

tvanfosson
Turns out I was on 'debug', but I was catching my own UnauthorizedAccessException from 1 line above in the same scope. I would have expected exception throwing to return me to the calling stack until a handler was found.This is how my code was laid out: if (!user.Identity.IsAuthenticated) throw new UnauthorizedAccessException(); string url = HttpContext.Current.Request.Url.AbsolutePath.ToLower();Thanks for pointing me in the right direction.
Matt