简体   繁体   English

通过不同的ASP会话在c#中维护变量

[英]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. 您好我有一个会话ID变量我正在从Oracle包传递到一个asp页面。 What I want to do is hold on to that variable and pass it back to Oracle through a different call. 我想要做的是坚持该变量并通过不同的调用将其传递回Oracle。 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. 我不太确定在这个问题上有多少信息太多或太少但基本上我有一个连接类,用不同的方法在Oracle中调用不同的proc。 Each one is called by pressing one of two buttons on the asp page. 通过按下asp页面上的两个按钮之一来调用每个按钮。

One method (on button click) will pass in the Session ID (along with cursor results that exist in a permanent Oracle table). 一种方法(按钮单击)将传递会话ID(以及存在于永久Oracle表中的游标结果)。

The asp page then displays the cursor results. 然后,asp页面显示光标结果。

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. 第二种方法(按钮单击)然后调用Oracle中的proc,以根据会话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. 为了确保传递正确的内容,我需要asp页面来保持会话ID(我得到了这个),然后在不同的调用中将它传递回Oracle。

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. 我是ASP的新手,所以对于为什么这些信息丢失的任何见解都表示赞赏。 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. 我会乐意用更多的代码进行推断,但不想提供任何不必要的东西。

Thanks. 谢谢。

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. 最后我添加了一个小方法,在aspx.cs中收集了sessionId,然后在回发后调用该方法。 All the troubles occurred when trying to set the value within the pre-init to page_load methods. 尝试将pre-init中的值设置为page_load方法时发生了所有问题。 By calling a separate method after the click events I was able to save and recall the sessionid successfully. 通过在单击事件后调用单独的方法,我能够成功保存并调用sessionid。

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 asp.net page. 如果该信息不易出现安全问题,一种方法是在asp.net页面上有一个隐藏字段。 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 获得sessionId后,您可以存储它

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; }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM