2

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.

  • Are you saying you're using a custom Profile Provider? Does that provider place data into Session?! That seems like a rube-goldberg machine. – JJS May 04 '15 at 17:49
  • @JJS - yes and yes. You say that like Rube Goldberg machines aren't cool, lol. I wrote it maybe 10 years ago during a port from a classic asp site. I suspect I did it that way because Profile seemed the place to put that information and the asp application used Session to store profile information. In retrospect, I probably should have used the Profile custom properties or maybe as a function on the custom Profile that accessed the Session. Either of which would solve the problem of instantiating the Profile object prior to accessing the Session. – John Eiford May 04 '15 at 19:12
  • Rube Goldberg machines ARE very cool, when they work, but they're a pain to maintain. If we knew today when we knew 10 years ago, we'd do it differently. Hindsight is 20/20. – JJS May 04 '15 at 19:14

1 Answers1

1

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.

JJS
  • 6,431
  • 1
  • 54
  • 70
  • Looks like I get an object of type ProfileCommon. But then the error disappears, which probably means that it's being instantiated when it's accessed. I'll check out the article. – John Eiford May 04 '15 at 16:28
  • How were you accessing profile before? and Yes, it is instantiated when accessed http://referencesource.microsoft.com/#System.Web/HttpContext.cs,bba8c379705d1d18 – JJS May 04 '15 at 16:29
  • I was calling a function that accessed the Session values (which should have been populated by the custom Profile). It's possible my code accessed the Profile on aspx pages before anything else though. I'll run a test. – John Eiford May 04 '15 at 17:45
  • ok, looks like the Profile is not instantiated by default on a default `System.Web.UI.Page`. My derived Page class prints out the user's name in the header, so it would always have been available. Thanks for those great resource links. – John Eiford May 04 '15 at 17:54
  • glad I could be of help. – JJS May 04 '15 at 19:15