Hi guys,
I am trying to protect a page using some custom code. We have a third party that submits a custom header. When the header is missing or invalid, I like to set a 401. I have something like this:
[Subscribe(Standard.Application.AfterBeginRequest)] public class BlockAccess : NotificationSubscriber { public override void OnNotify(string notification, NotificationArgs args) { if (MyCustomLogic()) { HttpContext.Current.Response.StatusCode = 401; HttpContext.Current.Response.StatusDescription = "Unauthorized"; HttpContext.Current.Response.End(); } } }
This works well and correctly blocks the access. However, in order to see which page to run this on, I need to access the Request.QueryString["ID"]:
int currentPageId = Convert.ToInt32(HttpContext.Current.Request.QueryString["ID"]);
That's available for Default.aspx?ID=123 but not for a friendly URL. I guess AfterBeginRequest kicks in before URLs are resolved. I looked at HttpContext.Current.Request but none of its properties contain a reference to the ID.
If I choose a later notification, like DeviceDetected, the same code returns a 200 OK with HTML saying "Response status code does not indicate success: 401 (Unauthorized)".
Is there a notification between these two that let me set the status code and have access to the page ID?
Thanks!
Imar