广西围捕2条大怪鱼,红娘子结局,教师两学一做心得体会
本文实例讲述了*.ashx文件不能访问session值的解决方法。分享给大家供大家参考之用。具体方法如下:
实例代码如下:
<%@ webhandler language="c#" class="producthandler" %> using system; using system.web; using jbtcard.entity.companyentity; using jbtcard.business.companybs; using system.collections.generic; using newtonsoft.json; using system.web.sessionstate; public class producthandler : ihttphandler, irequiressessionstate, ireadonlysessionstate{ public void processrequest (httpcontext context) { string moduleid = context.request.form["moduleid"].tostring(); string message = ""; switch (moduleid) { case "getptypelist": ilist<producttypeidnameentity> list = producttypebs.getptypelistidname(); message = javascriptconvert.serializeobject(list); break; case "getcompanybyid": int cid = convert.toint32(context.session["cid"]); companyentity company = companybs.getcompanyentybyid(1); message = javascriptconvert.serializeobject(company); break; case "insert": string condis = context.request.form["condi"].tostring(); productentity model = (productentity)javascriptconvert.deserializeobject(condis, typeof(productentity)); bool b = productbs.addproduct(model); if (b) { message = "{success:true}"; } else { throw new exception("商品添加失败!"); } break; } context.response.contenttype = "text/javascript"; context.response.write(message); } public bool isreusable { get { return false; } } }
其实只要加上这句就好了:
using system.web.sessionstate;
希望本文所述对大家的asp.net程序设计有所帮助
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
asp.net搭建博客,使用BlogEngine.NET+MySql搭建博客
网友评论