I want to access the user session from a web method. But when I check for the session object, its nothing! How can I access the current user's session from the webmethod?
My code:
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class DalService
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function AddFavourite(ByVal locationId As Integer) As Integer
Dim result As Integer = 0
If Session IsNot Nothing Then
'DO SOMETHING
Else
ReportError("SESSION IS NOTHING!!!!!!!??????", "")
End If
Return result
End Function
End Class
please mark answers as 'Answered' and post back solutions when you figure stuff out that isnt in the post already.
By default, ASP.NET session support for each Web method is turned off. You must explicitly enable session support for each Web method that wants to use session state. This is done by adding the
EnableSession property to the WebMethod attribute of your function.
<WebMethod(EnableSession:=True)> _
Public Function AddFavourite(ByVal locationId As Integer) As Integer
Dim result As Integer = 0..........
Peter Smith
Contributor
4605 Points
2109 Posts
Access the user session from a web method
Oct 29, 2010 07:55 AM|LINK
I want to access the user session from a web method. But when I check for the session object, its nothing! How can I access the current user's session from the webmethod?
My code:
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class DalService
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function AddFavourite(ByVal locationId As Integer) As Integer
Dim result As Integer = 0
If Session IsNot Nothing Then
'DO SOMETHING
Else
ReportError("SESSION IS NOTHING!!!!!!!??????", "")
End If
Return result
End Function
End Class
Steelymar
All-Star
15283 Points
2239 Posts
Re: Access the user session from a web method
Oct 29, 2010 08:11 AM|LINK
By default, ASP.NET session support for each Web method is turned off. You must explicitly enable session support for each Web method that wants to use session state. This is done by adding the EnableSession property to the WebMethod attribute of your function.
<WebMethod(EnableSession:=True)> _
Public Function AddFavourite(ByVal locationId As Integer) As Integer
Dim result As Integer = 0..........
http://msdn.microsoft.com/en-us/library/aa480509.aspx
Stefan Uzunov
MCTS: .NET Framework 3.5 ASP.NET Applications
Peter Smith
Contributor
4605 Points
2109 Posts
Re: Access the user session from a web method
Oct 29, 2010 05:22 PM|LINK
Thanks!