使用jquery在asp.net会话中存储值 [英] Storing values in asp.net session using jquery

查看:77
本文介绍了使用jquery在asp.net会话中存储值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用jquery在会话中存储值。
我使用以下代码

How to store values in the session using jquery. I am using the following code

var Link = '<%=Session["Link"]%>';

从会话中获取数据。如何进行逆向处理。

to get data from session. How to do the reverse process.

问题:

 I need this in my master page. so i cant use .ajax{}.

Geetha

推荐答案

您可能需要设置 HTTP处理程序或类似的东西将接受请求并在会话中存储事物。 Visual Studio在解决方案视图的添加菜单中有这个位置。 (如果您使用的是ASP.NET MVC,则只需设置另一个操作而不是通用处理程序。)

You will probably need to set up an HTTP handler or something similar that will accept requests and store things in the Session. Visual studio has this somewhere in the "Add" menus in the solution view. (If you're using ASP.NET MVC, you just set up another action instead of a generic handler.)

因为这些值可能有不同的类型(int,字符串,等等),因为您不希望恶意用户访问他们认为合适的任何会话密钥,您可能需要设置一个分支来确定如何处理每个密钥。像这样的东西(在你创建的处理程序中):

Since those values will may have different types (int, string, etc.) and since you don't want malicious users poking into any session key they see fit, you will probably want to set up a branch to determine what to do with each key. Something like this (inside the handler that you created):

string key = context.Request.QueryString["key"].ToString();
string val = context.Request.QueryString["val"].ToString();
if(key == "AshDiffuserID"){
  int ash_diffuser_id = Convert.ToInt32(val);
  Session["AshDiffuserID"] = ash_diffuser_id;
}
else if(key == "PesterchumHandle") {
  string handle = val;
  Session["PesterchumHandle"] = handle;
} else // etc...

之后,你需要设置通过jquery 发布HTTP请求,在密钥和密钥中放置您需要的任何值valfields。

After that, you'll need to set up a post HTTP request through jquery that puts whatever values you need in those "key" and "val" fields.

$.post(
  'url/to/your/handler.ashx',
  {key: "PesterchumHandle", val: "carcinoGenetecist"}
); 

这篇关于使用jquery在asp.net会话中存储值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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