加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何将会话参数从jquery传递到ASHX处理程序

发布时间:2020-12-16 00:17:52 所属栏目:百科 来源:网络整理
导读:下面是我的 Jquery代码,我想传递Session paramater,例如会话[ “ID”]. Jquery调用ASHX页面 以下所有参数都正常工作,session参数有一个值,但是如何从Jquery传递会话参数? 所以下面的代码“paramater Sessionparameter”应该替换为Session [“ID”]或类似的
下面是我的 Jquery代码,我想传递Session paramater,例如会话[ “ID”].
Jquery调用ASHX页面

以下所有参数都正常工作,session参数有一个值,但是如何从Jquery传递会话参数?

所以下面的代码“paramater Sessionparameter”应该替换为Session [“ID”]或类似的东西.我怎样才能做到这一点?

请指教?

$('input[name$=btnTab1Save]').click(
             function (e) {
                 // debugger;
                 // AJAX call to the handler
                 $.post(
                    'Consulting.ashx',// data to the handler in the form of QueryString
                    {
                    tab: 'tab1',// id is the second column within the row
                    Ilac_id: prevRow.find('td:eq(0)').text(),ID: SESSION_PARAMATER,begindate: $('input[name$=begindate]').val(),weigth: $('input[name$=weigth]').val(),continue: true,freq: $('input[name$=freq]').val(),reason: $('input[name*=radListreason]:checked').val(),freq2: $('input[name$=radListfreq2]:checked').val(),freetext: $('input[name$=freetext]').val()
                },// callback function
                 // data is the JSON object
                    function (data) {
                        if (data.Success) {
                            // close the tab
                        }
                    },"json"
                );
             });

我可以读取我的参数,如Convert.Toint(context.Request.Form [“ID”]));

data.weigth = Convert.ToInt32(context.Request.Form["weigth"]);

我试过:’<%= Session [“ID”] .ToString()%>‘,但它不起作用….

解决方法

如果信息在会话中,ASHX可以直接访问会话内容.

你需要实现IReadOnlySessionState,你会没事的.

<% @ webhandler language="C#" class="MyClass" %>

using System;
using System.Web;
using System.Web.SessionState;

public class MyClass: IHttpHandler,IReadOnlySessionState
{
   public bool IsReusable { get { return true; } }

   public void ProcessRequest(HttpContext ctx)
   {
       ctx.Response.Write(ctx.Session["ID"]);
   }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读