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"]);
1
  • 1
    Think your code snippet is wrong should be response.write("Session(oldID)=" & Session("oldID")). It's not important for the question mind. Commented Mar 24, 2016 at 16:10

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

2 Comments

Can you give me an example for your second method?(POST)
Thanks Bharat Gupta.
0

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){

}

2 Comments

Totally not relevant, you missed the part about Classic ASP here.
Oh! Yes, I see it now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.