[英]How can I persist a session when I redirect to another website in ASP.NET MVC
A website A makes a post to a website B, B says "OK" and store an object into a session. 网站A在网站B上发帖,B说“确定”并将对象存储到会话中。 A read the "OK" and then redirect the user to B. At that moment, the session object is null.
A读取“确定”,然后将用户重定向到B。这时,会话对象为null。 Both websites are in the same domain.
两个网站都在同一个域中。 I need to persist the object session when I make the redirect
进行重定向时,我需要保留对象会话
From MSDN "ASP.NET session state enables you to store and retrieve values for a user as the user navigates ASP.NET pages in a Web application." 来自MSDN,“ ASP.NET会话状态使您可以在用户浏览Web应用程序中的ASP.NET页面时为用户存储和检索值。”
You are talking about persisting values from one Web application to another, session state is not designed for that. 您所谈论的是将值从一个Web应用程序持久保存到另一个Web应用程序,会话状态并非为此而设计。
You will need to persist values to a store that is available to both applications such as ASP.Net cache or a database. 您将需要将值持久存储到两个应用程序都可以使用的存储中,例如ASP.Net缓存或数据库。
Although, as is pointed out above, session state can be configured to persist to a database, since IIS is managing that database via the session objects, it still prevents access of the session data cross application. 尽管如上所述,可以将会话状态配置为持久保存到数据库,但是由于IIS通过会话对象管理该数据库,因此它仍然阻止跨应用程序访问会话数据。
There's a lot of stars that have to align for this to work: 为了使它起作用,有很多星星需要调整:
The two sites must be on the same domain or subdomains of that domain. 这两个站点必须位于同一域或该域的子域中。 If you're dealing with two completely different domain names, you're flat out of luck.
如果您要处理两个完全不同的域名,那么您就走运了。
Both sites must have their session mode be a StateServer that they both can access or SQL Server. 两个站点的会话模式都必须是它们都可以访问的StateServer或SQL Server。 If SQL Server, you must persist the session in a database that can be accessed by both sites.
如果是SQL Server,则必须将会话保留在两个站点都可以访问的数据库中。
You'll need to configure the machine key for each site to be the same. 您需要将每个站点的机器密钥配置为相同。 See: https://technet.microsoft.com/en-us/library/cc755177%28v=ws.10%29.aspx
请参阅: https : //technet.microsoft.com/zh-cn/library/cc755177%28v=ws.10%29.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.