English 中文(简体)
使用jQuery将值存储在asp.net会话中。
原标题:Storing values in asp.net session using jquery

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

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

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

问题:

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

吉塔

最佳回答

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

由于这些值可能具有不同的类型(int,string等)由于您不希望恶意用户随意尝试进入任何会话密钥,您可能需要设置一个分支以确定如何处理每个密钥。类似这样(在您创建的处理程序内):

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设置POST HTTP请求,将您需要的任何值放入这些“键”和“值”字段中。

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

我浪费了整个白天来解决这个问题,而这只是一个快速修复。在调用PageMethod时,会话ID未随请求URL传递,因此会触发新的session_start事件。我们只需要在调用pagemethod之前设置确切的请求路径,以便不会触发新的会话启动事件。

if ( <%= HttpContext.Current.Session.IsCookieless %>==True ) {
//need to pass session id in request path
PageMethods.set_path( <%= System.Web.Configuration.WebConfigurationManager.AppSettings("WebRoot") %>(S(<%=Session.SessionID%>))/secure/PageName.aspx );
}
PageMethods.PageMethodName(param1,param2, CallSuccess, CallFailed);

您需要通过jQuery进行AJAX POST到服务器。





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签