I just find that the problem is not related to the webmethod.
It is caused by another problem.
I set the Session["PhotoId"]
in a normal aspx.
But I can't retrieve value in the webMethod
of the aspx page.
[WebMethod(EnableSession=true)]
public static string Submit(string data1, ...)
{
string test = HttpContext.Current.Session["PhotoId"]; // test is null
}
What should I do?
To enable the session in a web service it must use the EnableSession Property of the WebMethod attribute. It must set EnableSession to true as shown in the preceding example. Without setting the EnableSession property to true, the session will not work otherwise the unhandled exception occurs.
By using one of below codes, string test = Session["UserName"]; or u can test the session by below code.
As I see, everything should be fine here.
As far as HttpContext.Current.Session is not null, session state is supported here. Please ensure, that you set Session["PhotoId"].
You can test whether it is the same session by examining
HttpContext.Current.Session.SessionID
in both normal ASPX and WebMethod.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With