ashx文件使用的基类的实现
来源:互联网 发布:大连网络推广 编辑:程序博客网 时间:2024/05/18 00:55
在会员管理系统或者后台管理系统中。可以创建基类,以实现基本的验证,及一些公用的方法或函数。而对于网站中一些一般处理程序,也有类似的需求。实现方法
一、首先创建一个通用的ashx文件,其他页面要继承此文件,这里不能单独使用cs类来实现
BaseHandle.ashx
代码的实现:
/// <summary>
/// ashx页面统一调用的基类 的摘要说明
/// </summary>
public class BaseHandle : IHttpHandler, IRequiresSessionState
{ protected NiuMaiFacade facade = new NiuMaiFacade(); public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; //判断登录是否超时
if (!facade.CheckLogin()) { JSHelper.Write("登录超时,请重新登录"); context.Response.End(); } AjaxProcess(context); } public bool IsReusable { get
{ return false; } }
/// <summary>
/// 虚拟方法
/// </summary>
/// <param name="context"></param>
public virtual void AjaxProcess(HttpContext context) { }}
AjaxProcess这个方法必须,要在其他调用这个基类的页面中使用
二、调用方法
/// <summary>
/// ProductChangeState 的摘要说明
/// </summary>
public class ProductChangeState : BaseHandle
{ public override void AjaxProcess(HttpContext context) { context.Response.ContentType = "text/plain"; //上架||下架
if (RequestHelper.GetFormString("act") == "chgState") { //EventLog.WriteLog("b"); int iid = RequestHelper.GetFormString("Id").ToInteger(); int iState = RequestHelper.GetFormString("attr").ToInteger(); int iverify = 1; string strSql = string.Empty; if (RequestHelper.GetFormString("attr") == "1") { strSql = string.Format("update producta set iState={0},iverify={1} where iid={2}", iState, iverify, iid); } else { strSql = string.Format("update producta set iState={0} where iid={1}", iState, iid); } if (facade.ExecuteSql(strSql) > 0) { JSHelper.Write("ok"); context.Response.End(); } else { JSHelper.Write("操作失败,请与客服人员联系"); context.Response.End(); } } //作废操作
if (RequestHelper.GetFormString("act") == "chgDel") { if (!RequestHelper.GetFormString("Id").IsInteger()) { JSHelper.Write("参数错误"); context.Response.End(); } int iid = RequestHelper.GetFormString("Id").ToInteger(); string sql = string.Format("select istate from producta where iid={0}", iid); int istate = facade.GetScalarBySql(sql).ToInteger(); if (istate == 2) //如果是作废状态,则启用 { sql = string.Format("update producta set iState=0 where iid={0}", iid); } else //如果不是作废状态,则作废 { sql = string.Format("update producta set iState=2 where iid={0}", iid); } if (facade.ExecuteSql(sql) > 0) { JSHelper.Write("ok"); context.Response.End(); } else { JSHelper.Write("操作失败,请与客服人员联系"); context.Response.End(); } } context.Response.Write("参数错误"); } }
0 0
- ashx文件使用的基类的实现
- ashx文件的使用
- ashx文件的使用
- ashx文件的使用
- ashx文件的使用实例
- ashx文件的使用小结
- ashx文件的几种使用
- ashx 文件的运用
- ashx 文件的运用
- 创建安全的ashx文件,ashx编译
- 创建安全的ashx文件,ashx编译
- 使用.ashx文件处理IHttpHandler实现发送文本及二进制数据的方法。
- 使用.ashx文件处理IHttpHandler实现发送文本及二进制数据的方法
- 使用.ashx文件处理IHttpHandler实现发送文本及二进制数据的方法
- 使用.ashx文件处理IHttpHandler实现发送文本及二进制数据的方法(转)
- 使用.ashx文件处理IHttpHandler实现发送文本及二进制数据的方法
- 使用.ashx文件处理IHttpHandler实现发送文本及二进制数据的方法。
- 使用.ashx文件处理IHttpHandler实现发送文本及二进制数据的方法。
- 设计模式之组合模式
- 模仿与学习MyBatis - 1.2 DataSource与Session
- MyISAM和InnoDB的区别
- 文章标题
- Linux c==网络编程的理论知识
- ashx文件使用的基类的实现
- redis学习笔记(一)redis3.2.5集群安装与测试
- 获取appdelegate对象
- Gradle学习笔记(四)web项目
- Paterson算法
- ffmpeg源码分析与应用示例(一)——H.264解码与QP提取
- 他
- C# WinForm程序退出的方法
- Maven 3 可移植性