maintaining a variable in c# through different ASP sessions

Hello I have a Session ID variable I'm passing through from on Oracle package into an asp page. What I want to do is hold on to that variable and pass it back to Oracle through a different call. I would think this should be easy but I lose the variable value.

Everything else in the solution is working perfectly. It's just a small addition.

I'm not too sure how much information is too much or too little on this question but basically I have a connection class with different methods to call different procs in Oracle. Each one is called by pressing one of two buttons on the asp page.

One method (on button click) will pass in the Session ID (along with cursor results that exist in a permanent Oracle table).

The asp page then displays the cursor results.

The second method (on button click) then calls a proc in Oracle to pass whatever exists in that table to another Table based on the Session ID.

In order to ensure the right contents are passed I need the asp page to hold on to the session id (I got this far) then pass it back to Oracle on a different call.

in the declaration we have

private string outSessionID;

    public string OutSessionID
        get { return outSessionID; }
        set { outSessionID = value; }

section of the connection method that sets the parameter

addDbParameter(ref cmd, "outSession_ID", DbType.String, ParameterDirection.Output, null);

addDbParameter(ref cmd, "rc1", DbType.Object, ParameterDirection.Output, null);

 outSessionID = cmd.OutParameter<String>("outSession_ID");

in second method we have

addDbParameter(ref cmd, "inSession_ID", DbType.String, ParameterDirection.Input, OutSessionID);

I'm new to ASP so any insight on why this information is lost is appreciated. I think it has something to do with a postback being a new session or something but I'm not precisely sure.

I"ll be happy to extrapolate with more code but don't want to provide anything unnecessary.


Just to add that in the end I added a small method that collected the sessionId in the aspx.cs then called that method after ther postback. All the troubles occurred when trying to set the value within the pre-init to page_load methods. By calling a separate method after the click events I was able to save and recall the sessionid successfully.

Thanks for the responses, they were very helpful.


If that information is not security-prone, one approach is you can have a hidden field on your page. NOTE: the user can view the source of your page and see the content of the hidden field

<as:HiddenField runat="server" ID="MySessionID" />

Then after getting your sessionId you can store it

MySessionID.Value = outSessionID;

and to use it later

outSessionID = MySessionID.Value;

Here is another trick

public string OutSessionID
    get { return ViewState["outSessionID"].ToString(); }
    set { ViewState["outSessionID"] = value; }

Need Your Help

Storing tokenized text in the db?

python caching postgresql nlp tokenize

I have a simple question. I'm doing some light crawling so new content arrives every few days. I've written a tokenizer and would like to use it for some text mining purposes. Specifically, I'm using

How to restrict forceful browsing for resources (js,html,pdf,css,images)

security jsp web

This question is might be redundant, but I am not getting concrete answer while searching many reference.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.