如何将所有html保持在与webservice的会话中?

时间:2015-03-16 20:06:38

标签: jquery web-services

我希望使用webservice在会话中保留完整的html,但是 设置会话步骤抛出此异常。

  

对象引用未设置为对象的实例。

我的功能是

[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 "";
    }
}

1 个答案:

答案 0 :(得分:0)

在您的网络方法中,请确保启用会话

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

Reference