1

My ASP.NET web application consumes an internal RSS feed which uses the identity of the currently logged on user to customise its content. The RSS feed is generated by a standard .ashx handler in my application.

When I call the RSS feed using XElement.Load(rssFeedUri), the session state is not maintained (presumably because the session ID cookie is not being sent with the request).

The RSS feed is working as intended when called directly from the browser address bar for a logged in user. I have already ensured that my handler implements IRequiresSessionState so that if the session ID is passed to the service, I can access the session data.

Using the Visual Studio debugger, I have determined that a new session is being created when my feed is accessed via XElement.Load.

How can I load my RSS feed and ensure that session state is available to it?

Richard Fawcett
  • 2,799
  • 1
  • 29
  • 36

1 Answers1

2

You can do the below steps:

  1. Using WebClient class load the RSS URL content in a string. While using this WebClient class set the Cookies request header value same as the current web request Cookie header which have the session ID etc.
  2. Create String Reader from the string you get above
  3. use XElement.Load(str_reader)

I hope this will solve your problem

Ankur
  • 33,367
  • 2
  • 46
  • 72
  • That sounds like a good plan. However, in practice, once I've called webClient.Headers.Add("Cookie", existingCookieValue) then the call which executes the request seems to hang. Without adding the cookie header, the request returns quickly, but with a 403 Forbidden (as expected). Any ideas? – Richard Fawcett May 31 '11 at 12:13
  • Hmm not sure why is that so... One other option is to re-factor your handler logic in a normal class method and call that method which returns the RSS feed. This same method gets called from ProcessRequest of the Handler.. no need to go through URL path – Ankur May 31 '11 at 16:19
  • I'm guessing my webClient call was hanging because there's a limit of one concurrent request which uses session state for each session ID. http://stackoverflow.com/a/2327051/431891 – Richard Fawcett Mar 19 '12 at 09:49