把ASP应用中的Session传递给asp.net应用
例子如下
ASP應(yīng)用URL為http://127.0.0.1/asp/,并在ASP.NET應(yīng)用中的web.config設(shè)定
? <!--設(shè)定ASP應(yīng)用的URL-->
? <add key="aspURL" value="http://127.0.0.1/asp/" />
在ASP應(yīng)用中增加兩個(gè)ASP頁面system.asp和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>")
%>
在ASP.net應(yīng)用中用頁面getSession.aspx來接受傳遞過來的Session變量值
getSession.aspx.cs代碼片段:
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"];
????
??? //驗(yàn)證是否從asp應(yīng)用中提交過來
??? if(fromurl.StartsWith(aspurl))
??? {
???? string uid=Request["UID"].ToString();
???? string state=Request["isPass"].ToString();
????
???? ?if(uid!="" && state=="ok")
???? ?{
????? ?//表明用戶在asp系統(tǒng)中已登錄成功?
????
???? ?}
?
??? }
??? else
??? {
??? ?Response.Write("<script>alert('非法用戶或未登錄用戶');top.location.href='" + aspurl +
"';</script>");
????
??? }
????
?? }
?? catch
?? {
??? Response.Redirect(aspurl);
?? }
? }
}
當(dāng)然,上述例子只是為解決特定的問題,如果要寫成通用的,則需要做如下修改
就在autoPostForm.asp使用?
For each sItem in Session.Contents?
Response.Write("<input type=hidden name=" & sItem)?
Response.Write( " value=" & Session.Contents(sitem) & " >")?
next?
而在getSession.aspx頁面用下面的代碼來接受并用同名Session變量保存?
for(int i=0;i<Request.Form.Count;i++)?
{?
Session[Request.Form.GetKey(i)]=Request.Form[i].ToString();?
}?
轉(zhuǎn)載于:https://www.cnblogs.com/top5/archive/2010/08/06/1794086.html
總結(jié)
以上是生活随笔為你收集整理的把ASP应用中的Session传递给asp.net应用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 动态调用WCF服务[转]
- 下一篇: 南京一研究所回应招聘“硕士保安”:非普通