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