0

I want to keep that full html in my page in session using with webservice but set session step throw this exception.

Object reference not set to an instance of an object.

My functions are

[WebMethod(Description = "Gsetsession")]
[ScriptMethod(UseHttpGet = false)]
public void SetSession(string html)
{
    HttpContext.Current.Session["html"] = html;
}

[WebMethod(Description = "GetSession")]
[ScriptMethod(UseHttpGet = false)]
public string GetSession()
{
    if (HttpContext.Current.Session["html"] != null)
    {
        return HttpContext.Current.Session["html"].ToString();
    }
    else 
    {
        return "";
    }
}
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
mguzel
  • 1
  • 3
  • possible duplicate of [How can I access session in a webmethod?](http://stackoverflow.com/questions/4758575/how-can-i-access-session-in-a-webmethod) – Grundy Mar 16 '15 at 20:14

1 Answers1

0

In your web methods, make sure you enable session

[ WebMethod(Description="Get Session",EnableSession=true)]

Reference

AaronS
  • 7,649
  • 5
  • 30
  • 56