Reputation: 5
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"]);
Upvotes: 0
Views: 1949
Reputation: 2706
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
Upvotes: 3
Reputation: 521
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){
}
Upvotes: -1