I need to set a session in all webservice method call. So I decided to write it in constructor. But I can't assign it in Webservice constructor.
I know (EnableSession = true) is the attribute of WebMethod.
Any other suggestions?
If you want to set Session in constructors, you could refer to the below links. By the way, is your application built by MVC. The examples I provided is related with MVC.
Participant
1274 Points
386 Posts
Set session in webservice constructor
Jan 06, 2015 05:58 AM|Zinnia|LINK
Hi All,
I need to set a session in all webservice method call. So I decided to write it in constructor. But I can't assign it in Webservice constructor.
I know (EnableSession = true) is the attribute of WebMethod.
Any other suggestions?
LD
MCP, MCTS, MCPD
Contributor
5642 Points
944 Posts
Re: Set session in webservice constructor
Jan 07, 2015 01:57 AM|Archer Wang|LINK
Hi Zinnia,
As you said , you could set the porperty EnableSession = true to achieve your goal.
Below links are about how to use WebMethodAttribute to achieve your goal.
http://msdn.microsoft.com/en-us/library/ts05c1zw(v=vs.110).aspx
http://msdn.microsoft.com/en-us/library/system.web.services.webmethodattribute.enablesession(v=vs.110).aspx
http://weblogs.asp.net/anasghanem/avoid-using-the-session-in-the-page-constructor
Hope this could be helpful to you.
Best Regards,
Archer Wang
Participant
1274 Points
386 Posts
Re: Set session in webservice constructor
Jan 07, 2015 02:54 AM|Zinnia|LINK
Thank you. But EnableSession attribute can only set for methods, not for constructors.
LD
MCP, MCTS, MCPD
Contributor
5642 Points
944 Posts
Re: Set session in webservice constructor
Jan 12, 2015 02:34 AM|Archer Wang|LINK
Hi Zinnia,
If you want to set Session in constructors, you could refer to the below links. By the way, is your application built by MVC. The examples I provided is related with MVC.
http://stackoverflow.com/questions/6000852/i-want-to-use-session-in-the-asp-net-mvc-controller-constructor
http://stackoverflow.com/questions/2425566/asp-net-mvc-is-session-available-at-any-point-during-controller-construction
http://forums.asp.net/t/1520025.aspx?Session+in+constructor
Best regards,
Archer Wang