Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Reading and setting session values View modes: 
User avatar
Member
Member
egarrison-wte - 12/26/2012 3:28:53 PM
   
Reading and setting session values
I am finding myself using lots of custom controls because I need to write to and read from the session values. Is there a better way to do this without custom controls? K# or Macro syntax I have overlooked.

Here is an example of me reading a value:

object o = SessionHelper.GetValue("AdminToken");


Is there syntax to pass this in a Webpart or to SQL Statements? For security reasons, I cannot write to cookies. I also need to kill the session values (which happens) so that is why I need them in Session.

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 12/27/2012 5:52:27 AM
   
RE:Reading and setting session values
Hi,

You can use the sessions in a standard way as they are used in the ASP.NET, e.g.
HttpContext.Current.Session["session_var_ID"];

Please, take a look at the following article: Exploring Session in ASP.NET.

If you will download our API Documentation you will be able to list all availiable methods with the SessionHelper Class... GetValue, SetValue, Clear, Remove, etc.

Best regards,
Martin Danko

User avatar
Member
Member
egarrison-wte - 12/27/2012 2:53:15 PM
   
RE:Reading and setting session values
What is the syntax for usage in a transformation?

<td> SID: <%# HttpContext.Current.Session["session_ID"] %></td>

It is not giving an error but we are also not getting the session ID. In my custom control on the same page, I get the session_ID, so I am sure the Session ID is not null.


User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 12/28/2012 5:18:32 AM
   
RE:Reading and setting session values
Hi,

The example I described before should be used if you want to get the value of any variable stored in the session.

If you want to get just the Session_ID, in the transformation you can use:
<%#CMS.GlobalHelper.SessionHelper.GetSessionID()%>
or
<%#HttpContext.Current.Session.SessionID%>

Best regards,
Martin Danko

User avatar
Member
Member
egarrison-wte - 12/30/2012 8:35:37 AM
   
RE:Reading and setting session values
I have that mostly working. In a Transformation It is working fine.
<%#CMS.GlobalHelper.SessionHelper.GetValue("AdminID")%>
OUTPUTS value 59 Properly.
SQL QUERY TEXT in Custom SQL Datasource Webpart.  
EXEC CU_Proc_LogAction {%CurrentUser.UserSettings.ItemsAsFields.MemberNumber%}

Only returns a 1 Ever. No error. But not getting the session value.

SQL DEBUG Shows:

EXEC CU_Proc_LogAction 3400 , 'StmSum', 200053,1

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 1/8/2013 2:15:09 AM
   
RE:Reading and setting session values
Hi,

Could you please tell me where are you using this code?
Is there a way how can I reproduce this error? Thanks!

Best regards,
Martin Danko

User avatar
Member
Member
bryanallott - 2/11/2013 12:07:39 AM
   
RE:Reading and setting session values
Did you ever get to to the bottom of being able to read session values from webparts using macro/k# syntax?

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 2/16/2013 9:53:31 AM
   
RE:Reading and setting session values
Hi Bryan,

I would recommend you to create a Custom macro. You can use the standard ASP.NET methods or our API there.

Best regards,
Martin Danko