开发者

Not able to Get the session values in class library

开发者 https://www.devze.com 2023-01-24 13:43 出处:网络
This is the my first post and i am very excited to speak with you all experts and learn . I have added objects to the session state in an aspx page which is using an object datasource.I want toget th

This is the my first post and i am very excited to speak with you all experts and learn .

I have added objects to the session state in an aspx page which is using an object datasource.I want to get the session value in the class library which is used by th开发者_开发知识库e object datasource.

code in class library

selectedrelease = HttpContext.Current.Session["selectedbuild"].ToString();

code in aspx page

HttpContext.Current.Session["selectedbuild"] = TreeView1.SelectedNode.Text;

However i am not able to get the session value in class library Please help Many Thanks for the help in advance Rahul


I think a good idea is to structure your code so that you work with these values as parameters passed from one context to the other. Maybe right now you read your data from the session state but tomorrow you'll have to read it from the query string or some control on a page. Maybe you'll even find another use for the same piece of code that fills the datasource but you'll be stuck because it's not flexible enough.

So what I suggest is to not attempt to read that value directly from some specific source but expect it as a parameter.

Specific to your current issue, it's normal that you can only access the Session state from the context of the web application itself, not from a distinct library.


You have to pass the values from the session which you need in your library as parameters. Separating gui and logic is always a good idea.

0

精彩评论

暂无评论...
验证码 换一张
取 消