2 asp.net web应用程序之间共享相同的SessionID [英] Share same SessionId between two asp.net web applications
问题描述
我用了两个Web应用程序之间的SQL Server会话模式。
会话ID是在ASPState的数据库中创建。我需要分享第一次申请到第二会话ID不使用查询字符串和饼干。我跟着从这个<一个步骤href=\"http://stackoverflow.com/questions/2868316/sharing-sessions-across-applications-using-the-asp-net-session-state-service\">link.下面是code。
在这两个应用程序的(web.config文件)
I used a sql server session mode between two web applications.
The session id is created in the ASPState database. I need to share the session id from first application to second without using querystring and cookies. I followed the steps from this link. Below is the code.
In both apps (web.config)
<add name="DBConnection" connectionString="Data Source=localhost;DataBase=ASPState;Integrated Security=True;uid=sa;pwd=password-1" providerName="System.Data.SqlClient"/>
<sessionState mode="SQLServer" sqlConnectionString="DBConnection" allowCustomSqlDatabase="true" regenerateExpiredSessionId="false" cookieless="false" timeout="1" ></sessionState>
<machineKey validationKey="566A547C407CB0C47ABAEC581B8B90C45E15039806352E4611B35E0FB70C1C096350A4BBAE816191331DCA55874D3F96B41FFDED4C6A913591684A90825F53A0" decryptionKey="B299127DFC22648C2EF92D7EDF2E4960277F562C60F3BDE4A4C3BFDFEA602FDF" validation="SHA1" decryption="AES" />
<modules runAllManagedModulesForAllRequests="true">
<add name="BasicAuthenticationModule" type="UserAuthenticator" />
</modules>
在第一个应用程序的 Home.aspx.cs
protected void imgBTN_Click(object sender, EventArgs e)
{
string sessionKey = HttpContext.Current.Session.SessionID;
//How to transfer the same session id to the second application
Response.Redirect("http://localhost:43392/PartnerHome.aspx"");
}
我从ASPState的数据库会话密钥。但是,如何从相同的会话ID的第二个应用程序通过?
I got the session key from ASPState database. But how to pass from the same session id to the second application ?
推荐答案
您可以使用是SessionManager设置,无论你在目标网站想要的ID。你只需要通过查询字符串获取从一个传递或形成POST其他:
You can use SessionManager to set the ID to whatever you want in the target site. You just need to pass it via querystring GET or form POST from one to the other:
来源
Response.Redirect("http://localhost:43392/PartnerHome.aspx?SessID="
+ Session.SessionID);
目标
string sessionId = Request.QueryString["SessId"];
bool redirected = false;
bool isAdded = false;
new System.Web.SessionState.SessionIDManager().SaveSessionID(
HttpContext.Current, sessionId, out redirected, out isAdded);
这篇关于2 asp.net web应用程序之间共享相同的SessionID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!