Search code examples
asp.nethttphandlerashxprofile-provider

How do I instantiate the Profile from an ashx file?


I recently switched some AJAX queries to use ashx files instead of aspx, having discovered that Response.End is no longer in vogue. In the case I'm looking at now, the submission of a purchase order is handled by the ashx. The user clicks the Submit button on the PO and the ashx file records the time and the user in a database table. An object with the current user's data (including their primary key) is stored in the Session and is recorded there by a custom Profile Provider. I have added IReadOnlySessionState in order to be able to access the Session, but it appears that, unless another .net page has been accessed, the Profile Provider doesn't run and the Session has no values. (verified by stepping through the code.)

I tried IRequiresSessionState, but the same results.

I'm assuming that the System.Web.UI.Page HttpHandler instantiates the custom Profile if it hasn't been already and that I'll need to add that to my custom HttpHandler.

I looked briefly at HttpModules, but I don't think that's what I want because they load for each request.


Solution

  • What is the value of HttpContext.Current.Profile? The Profile property is populated during the AcquireRequestState stage of the Request lifecycle by the built in HttpModule ProfileModule.

    There is great info here http://odetocode.com/articles/440.aspx on how the internals work.