Transfer the session in ASP application to asp.net application

Source: Internet
Author: User
Tags tostring
Asp.net|session

Recently to do a business processing system, because its original user system using ASP development, in the new business system used asp.net,asp.net application to use the original ASP user system, so the problem arises, ASP Application How to make the user login status and user information in the asp.net still valid. We then consider using the construct form to derive the session variables from the dynamic commit delivery ASP application.
Examples are as follows
ASP application URL for http://127.0.0.1/asp/, and in the ASP.net application of web.config settings
<!--set the url--> of ASP application
<add key= "Aspurl" value= "http://127.0.0.1/asp/"/>

Add two ASP pages system.asp and autopostform.asp in ASP applications
<!--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>")
%>

Use page getsession.aspx in asp.net application to accept the value of the session variable passed over

GetSession.aspx.cs Code fragment:
private void Page_Load (object sender, System.EventArgs e)
{

if (! Page.IsPostBack)
{
String aspurl=configurationsettings.appsettings["Aspurl"]. Trim ();
Try
{
String fromurl=request.servervariables["Http_referer"];

Verify whether to submit from ASP application
if (Fromurl. StartsWith (Aspurl))
{
String uid=request["UID"]. ToString ();
String state=request["Ispass"]. ToString ();

if (uid!= "" && state== "OK")
{
Indicates that the user has logged on successfully in the ASP system

}

}
Else
{
Response.Write ("<script>alert" (' illegal user or not logged in user '); top.location.href= ' "+ Aspurl +

"';</script>");

}

}
Catch
{
Response.Redirect (Aspurl);
}

}
}


Http://aspsir.cnblogs.com/archive/2005/12/24/41802.html




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.