我怎样才能触发会话启动(Global.asax中)事件的WebHandler请求? [英] How can I trigger Session Start (Global.asax) Event for a WebHandler Request?

查看:136
本文介绍了我怎样才能触发会话启动(Global.asax中)事件的WebHandler请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在我的asp.net项目请求生成图像的Webhandler。但是,如果用户直接访问资源时,不会触发Global.asax文件会话开始事件。但在我的项目,我需要触发会话开始事件。我怎样才能做到这一点?

 无效在session_start(对象发件人,EventArgs的发送)
    {
        会话[测试] = 1;    }


解决方案

每当一些服务器端的处理程序试图读取或写入到会话的在session_start 事件trigerred。你可以尝试装饰与<一个处理程序href=\"http://msdn.microsoft.com/en-us/library/system.web.sessionstate.irequiressessionstate.aspx\"><$c$c>IRequiresSessionState标记接口:

 公共类MyHandler的:IHttpHandler的,IRequiresSessionState
{
    ...
}

I have a Webhandler which generates an image on request in my asp.net Project. But if the user directly access the resource, it won't trigger the session start Event in the Global.asax file. But in my project I need to trigger the session start event. How can I achieve this?

 void Session_Start(object sender, EventArgs e) 
    {
        Session["Test"] = 1;

    }

解决方案

The Session_Start event is trigerred whenever some server side handler attempts to either read or write to the session. You might try decorating your handler with the IRequiresSessionState marker interface:

public class MyHandler: IHttpHandler, IRequiresSessionState
{
    ...
}

这篇关于我怎样才能触发会话启动(Global.asax中)事件的WebHandler请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆