Saving values ​​in an asp.net session using jquery

How to save values ​​in a session using jquery. I am using the following code

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

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

Problem:

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

Gita

+2
source share
3 answers

You 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 menu in the solution view. (If you are using ASP.NET MVC, you are simply setting up a different action instead of a generic handler.)

Since these values ​​can be of different types (int, string, etc.), and since you do not want malicious users to tinker with any session key, they deem it necessary, you probably want to configure the branch to determine what to do with each key. Something like this (inside the handler 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... 

After that, you will need to configure the post HTTP request through jquery, which places any values ​​that you need in these "keys" and the "val" field.

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

I spent all my day sorting out this issue while it is just a quick fix. During a PageMethod call, the session identifier is not passed with the request URL, so a new session_start event is fired. We just need to set the exact request path before calling pagemethod, so that a new session start event cannot be fired.

 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); 
+1
source

You will need to make an ajax message on the server through jquery.

0
source

All Articles