当前位置:编程学习 > C#/ASP.NET >>

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 = 网页特效convert.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;
        }
    }

}

补充:asp.net教程,.Net开发 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,