在Handler.ashx文件中使用session
使用jquery调用handler文件中的方法,需要使用session,默认生成的文件中,不可以直接使用session。按照以下步骤,即可以通过session与其他的aspx页面的session进行数据交互。
1,加入命名空间 using System.Web.SessionState;
2,在类的接口中添加IRequiresSessionState :public class ProjectInfo : IHttpHandler, IRequiresSessionState
3,引用session的方法:HttpContext.Current.Session["testSession"]。如果不加前缀会找不到。
按照以上方法就可以正常使用session。
Handler.ashx文件中,程序的入口只有ProcessRequest方法,如果要调用其他的方法,需要在ProcessRequest方法中通过参数来区分。
ajax方法:
function CheckPlanFinishDate() {
var strPlanDate = $("#txtPlanFinishDate").val();
var ProPNum = $("#ProPNum").val();
var Page = 1;
$.ajax({
type: "GET",
contentType: "application/json;utf-8",
url: 'handler/ProjectInfo.ashx?type=CheckPlanDateStatus&PlanDate=' + strPlanDate + '&ProPNum=' + ProPNum + '&Page=' + Page,
success: function(msg) {
if (msg == "1") {
art.dialog.tips('项目计划时间改变,请重新做会签!', 2);
}
}
Handler.ashx代码:
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
if (context.Request["type"] == "CheckPlanDateStatus")
{
string strpropNum = context.Request["ProPNum"];
string strPlanDate = context.Request["PlanDate"];
string strResult = CheckPlanDate(strpropNum, strPlanDate);
context.Response.Write(strResult);
context.Response.End();
}
}
CheckPlanDate是handle.ashx页面的一个普通方法。
在Handler.ashx文件中使用session的更多相关文章
- ashx文件中使用session提示“未将对象引用设置到对象的实例”
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Data;u ...
- 解决在.ashx文件中判断Session 总是NULL的方法
实现IHttpHandler接口的同时必须继承IRequiresSessionState接口,才能拿到session public class HttpHandler: IHttpHandler, I ...
- ashx页面中context.Session["xxx"]获取不到值的解决办法
在 aspx和aspx.cs中,都是以Session["xxx"]="aaa"和aaa=Session["xxx"].ToString()进 ...
- ashx文件要使用Session
ashx文件要使用Session,必须实现Session接口; using System;using System.Web;using System.Web.SessionState; //第一步:导 ...
- 解决ashx文件下的Session“未将对象引用设置到对象的实例”
using System; using System.Collections.Generic; using System.Linq; using System.Web; using PPT_DAL; ...
- 如何在web.config文件中配置Session变量的生命周期
实例说明:在网上购物商城中,为了维护在线购物环境,一般只有注册会员才可以购买商品.实现购物功能时,先通过Session变量记录会员的登录名,然后在购买商品页面通过判断会员是否登录确定其能否购买商品. ...
- 在ashx和静态文件中使用Session
在ashx页面中如果想使用可读可写的Session,必须要实现一个接口“IRequiresSessionState”,在这个接口中没有定义任何方法,这样的接口被称为“标识接口”. public int ...
- asp.net中ashx文件如何调用session
如果你要保证数据的安全性,你可以在ashx中使用session验证.如:你的index.aspx中使用jquery回调ashx数据,那么在index.aspx page_load时session[&q ...
- 在ashx文件中制作验证码(使用session要继承IRequiresSessionState)
必须继承System.Web.SessionState.IRequiresSessionState接口,才能实现Session读写! System.Web.SessionState的一些接口 IRea ...
随机推荐
- java传递和返回对象
java传递的只是一个引用,一定要注意准确认识在对象传递和赋值时所发生的一切. 事实上,java中的每个对象(除了基本数据类型以外)的标识符都属于指针的一种,但是其使用受到了严格的限制和防范,不仅在编 ...
- OpenCV installation on Linux
Getting the Cutting-edge OpenCV from the Git Repository Launch Git client and clone OpenCV repositor ...
- 一种json生成html的思路
输入: [{ tag:"ul", attribute:{ class:"father6" }, property:{ className:"fathe ...
- MyEclipse启动Tomcat服务器时老是跳到Debug调试上
window->preferences->Myeclipse->Servers->Tomcat 然后找到你的相应的Tomcat服务器的版本, 选中然后展开其下面的子菜单会发现有 ...
- SQL笔记(1)索引/触发器
--创建聚集索引 create clustered index ix_tbl_test_DocDate on tbl_test(DocDate) GO --创建非聚集索引 create nonclus ...
- Forbidden You don't have permission to access / on this server. You don't have permission to access /phpmyadmin/ on this server. 解决办法
Forbidden You don't have permission to access / on this server. 解决办法 打开 httpd.conf 文件, 将 # onli ...
- Python的lambda表达式
使用lambda来创建匿名函数,而用def创建的方法是有名称的,除了从表面上的方法名不一样外,python lambda还有哪些和def不一样呢? 1 python lambda会创建一个函数对象,但 ...
- (二)程序中的内存&&栈
一.程序运行为什么需要内存?基本概念? 内存是程序运行的立足之地,程序需要用内存来存储一些变量. 内存管理最终是由操作系统完成的,内存在本质上是一个硬件器件,由硬件系统提供:内存由操作系统统一管理,为 ...
- [css] 垂直居中方法
原文链接:http://www.cnblogs.com/2050/p/3392803.html 一.text-algin:center; 适用于行内元素水平居中,如图片.按钮.文字, 但是在IE67下 ...
- java中如何把后台数据推送到页面上 【后续编辑】
https://my.oschina.net/yongqingfan/blog/535749 http://www.blogjava.net/BearRui/archive/2010/05/19/fl ...