views:

137

answers:

2

Looks like context parameter of asp:net substitution control method is missing the current session once the page is output cached.

Aside from getting the substitution control's content thru ajax or using some other method to store data that would otherwise be in session (like database) is there anything else I can do?

Is there a workaround to use native asp.net session in substitution control?

<asp:Substitution  ID="myid" MethodName="method1"></asp:Substitution>

public static string method1(HttpContext context) <--  [1]

[1] --- conext.session is null after page is cached

A: 

What happens if you ensure that context.Session isn't null before accessing the value? I've had session problems before, not when using the Substitution control though, because Context.Session isn't set for the first request a user makes. You may be having a related problem as it wouldn't sit in the standard page lifecycle.

According to ScottGu everything should be available.

This static method will be passed an HttpContext object at runtime that contains the standard ASP.NET Request, Response, User, Server, Session, Application intrinsics, and which you can then use ...

Tip/Trick: Implement "Donut Caching" with the ASP.NET 2.0 Output Cache Substitution Feature

toxaq
[This page](http://forums.asp.net/p/1384173/2939887.aspx) seems to solve the same problem relating to the same info from that article. However it does seem that because substitution requests sit outside the page lifecycle you won't have access to the session. Could you grab the information from the cache or user object instead?
toxaq
A: 

From the same blog.

re: Tip/Trick: Implement "Donut Caching" with the ASP.NET 2.0 Output Cache Substitution Feature

Friday, February 23, 2007 1:30 AM by ScottGu

Hi Scott,

I think the error you are seeing is because you are trying to access the session object.

Unfortunately I don't think you can access the session in this scenario - since the session object is never populate (since the page is never created).

Sorry!

Scott

teddy