asp.net - Accessing session through pagemethods throw webServiceError when connecting to SQL Server -
i have problem accessing values in session through pagemethods when try connecting sql server.
i have uploadengin.aspx
page uploading files , monitoring upload state store state value (like 10%) in session. in uploadengin.aspx
page connecting sql server valid extension files. have basic problem. example below show sample code:
uploadengin
:
protected void page_load(object sender, eventargs e) { this.session["s"] = "hello"; if (!ispostback) { admin.app.core.attachment.attachmenttype att = new app.core.attachment.attachmenttype(); att.getextentionandmainpath("image"); } } [system.web.services.webmethod(enablesession = true)] public static string g() { return httpcontext.current.session["s"].tostring(); }
javascript:
(function () { window.onload = function () { pagemethods.g(function (r) { alert(r); }, function (r) { console.log(r); }); } })();
getextentionandmainpath:
public string[] getextentionandmainpath(string name) { string[] ext =new string[2]; string x = name; uint64 id = findidbyname(x); datatable dt = new dataaccess().executeselect("select_ano_attachmenttype", commandtype.storedprocedure, new dataparam("@id", id, sqldbtype.bigint)); if (dt.rows.count > 0) { ext[0] = dt.rows[0]["attachmenttype_validextention"].tostring(); ext[1]= dt.rows[0]["attachmenttype_mainpath"].tostring(); } return ext; }
without code inside if(!ispostback)
works fine , see "hello" message. when use code (connecting sql server valid extension),
webserviceerror: object reference not set instance of object
how should solve problem?
you need set enablesession
property on webmethod
attribute in order access session
values in web method.
[webmethod(enablesession = true)] public static string g() { return httpcontext.current.session["s"].tostring(); }
for more details, please refer msdn link.
Comments
Post a Comment