0

I have a .asp code which I generate several session variables in it and then I redirect it to a c# doe. I am trying to read these session variables which are coming from the.asp code into my C# code, but it seems that I cannot pass those into my c# code. I can get the value of the session variables while I am still on .asp part but as soon as I redirect to c# code and try to get the session variables(and value of them), the value does not come through.

asp part:

response.write("Session(oldID)=&Session("oldID"))

c# part:

string oldIDSession = (string)(Session["oldID"]);
mason
  • 31,774
  • 10
  • 77
  • 121
Shab
  • 5
  • 8
  • 1
    Think your code snippet is wrong should be `response.write("Session(oldID)=" & Session("oldID"))`. It's not important for the question mind. – user692942 Mar 24 '16 at 16:10

2 Answers2

3

The Classic ASP web application and the ASP.NET web application (C# code) are run in separate application domains of IIS and hence the session values cannot be shared.

You can share the required data to the ASP.NET (C#) web application using query strings or making a direct post request to the C# code.

Refer this post to know about passing data to C# page using query string.

Or, for posting the data using POST (in case you need to send lots of data to c# code) change the action attribute of the form in asp page to the c# (aspx page) to which the data should be posted.

EDIT

In the classic asp page you need to do something like (refer this):

<form action="http://example.com/TestApp/YourPage.aspx" method="post">
    // form elements
</form>

And then, to read the posted values in your c# page you need to use (refer this):

string paramValue = Request.Form["key"]; // where key is the parameter name
Community
  • 1
  • 1
Bharat Gupta
  • 2,628
  • 1
  • 19
  • 27
-1

Please refer to this post

I am not sure scale or nature of your application but I would suggest not to make your C# classes dependent upon session, they would be easy to test. For example.

//In your Asp.Net
int productId = (int)Session["productId"];

//In you c# code
public Product GetProductById(int productId){

}
Community
  • 1
  • 1
vabii
  • 521
  • 6
  • 16