Click here to Skip to main content
15,792,540 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to save the user signature as UserNameSig.png.
the code works but Session["UserNameSig"].ToString()
I Suspect that the [WebMethod()] ie having problems with the session variable.
Do anyone know how can solve this.


What I have tried:

        public static void UploadPic(string imageData)

            string Pic_Path = HttpContext.Current.Server.MapPath(Session["UserNameSig"].ToString() + ".png");
            using (FileStream fs = new FileStream(Pic_Path, FileMode.Create))
                using (BinaryWriter bw = new BinaryWriter(fs))
                    byte[] data = Convert.FromBase64String(imageData);
Updated 31-May-18 7:16am
Gerry Schmitz 30-May-18 17:39pm    
Iterate over your "session variables" and see (display) what you DO have; then go from there.

Session is an instance property. You cannot access it from a static method.

Instead, you will need to use HttpContext.Current to access the session:
HttpContext context = HttpContext.Current;
string Pic_Path = context.Server.MapPath(context.Session["UserNameSig"].ToString() + ".png");
Share this answer
I googled "webmethod session" and found these and many others

ASP.Net Web Services – How to use session state in a web service?[^]

Using ASP.NET Session State in a Web Service[^]

Please do basic research yourself like using google before asking a question.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900