Pass session in ASP application to Asp.net Application

Source: Internet
Author: User
ASP. NET application must use the original ASP user system, so the problem arises. How can ASP application make the user login status and user information remain valid in ASP. NET. Therefore, we consider using a form to automatically submit and pass session variables in ASP applications.
Example:
ASP application URL is Http: // 127.0.0.1/asp/ And web. config settings in ASP. NET Applications
<! -- Set the URL of an ASP application -->
<Add key = "aspurl" value =" Http: // 127.0.0.1/asp/ "/>

Add two ASP pages: system. asp and autopostform. asp
<! -- System. asp -->
<%
Session ("uid") = "user"
Session ("ispass") = "OK"
Server. Transfer ("autopostform. asp ")
%>

<! -- Autopostform. asp -->
<%
Response. Write ("<form name = T id = T action = ""Http: // 127.0.0.1/aspdotnet/getsession. aspx""

Method = post> ")
Response. Write ("<input type = hidden name = uid ")
Response. Write ("value =" & SESSION ("uid") & "> ")
Response. Write ("<input type = hidden name = ispass ")
Response. Write ("value =" & SESSION ("ispass") & "> ")
Response. Write ("</form> ")
Response. Write ("<SCRIPT> T. Submit (); </SCRIPT> ")
%>

In the Asp.net application, the getsession. ASPX page is used to accept the passed session variable value.

Getsession. aspx. CS Code Fragment:
Private void page_load (Object sender, system. eventargs E)
{

If (! Page. ispostback)
{
String aspurl = configurationsettings. receivettings ["aspurl"]. Trim ();
Try
{
String fromurl = request. servervariables ["http_referer"];

// Verify whether the application is submitted from ASP
If (fromurl. startswith (aspurl ))
{
String uid = request ["uid"]. tostring ();
String state = request ["ispass"]. tostring ();

If (UID! = "" & State = "OK ")
{
// Indicates that the user has successfully logged on to ASP.

}

}
Else
{
Response. Write ("<SCRIPT> alert ('invalid user or user not logged in '); top. Location. href ='" + aspurl +

"'; </SCRIPT> ");

}

}
Catch
{
Response. Redirect (aspurl );
}

}
}

Of course, the above example is just to solve specific problems. If you want to write it as common, you need to make the following modifications:
It is used in autopostform. asp.

For each sitem in session. Contents
Response. Write ("<input type = hidden name =" & sitem)
Response. Write ("value =" & session. Contents (sitem) & "> ")
Next

On the getsession. ASPX page, use the following code to accept and save it with the session variable of the same name.

For (INT I = 0; I <request. Form. Count; I ++)
{
Session [request. Form. getkey (I)] = request. Form [I]. tostring ();
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.