简体   繁体   English

当我重定向到ASP.NET MVC中的另一个网站时如何保持会话

[英]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: 为了使它起作用,有很多星星需要调整:

  1. 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. 如果您要处理两个完全不同的域名,那么您就走运了。

  2. 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,则必须将会话保留在两个站点都可以访问的数据库中。

  3. 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.

相关问题 我如何重定向一个ASP.NET MVC2页面 - How can I redirect an asp.net mvc2 page 如何重定向到ASP.NET MVC 3中的错误页面? - How can I redirect to an error page in asp.net mvc 3? 如何从ASP.NET MVC中的同一操作重定向到另一个视图或外部站点? - How can I redirect to either another view or an external site from the same action in ASP.NET MVC? 超时后,如何将用户重定向回退出页面? Asp.net MVC - How can I redirect a user back to signout page when timed out? Asp.net MVC 完成动作后,如何在ASP.NET MVC中将某人从一个动作重定向到另一个动作? - How do I redirect someone from one action to another in ASP.NET MVC when an action has completed? 如何读取在ASP.NET MVC中分配给Session的对象的属性? - How can I read the properties of an object that I assign to the Session in ASP.NET MVC? ASP.NET MVC即使没有人访问该网站,我也可以始终运行循环吗? - ASP.NET MVC Can I have a loop always be running even when no one visits the website? 如何在 ASP.NET MVC 中保存登录 session - How do I save Log In session in ASP.NET MVC ASP.NET Core 2.0/Razor Pages - 如何在请求之间将数据保存在 NonFactors MVC6 网格中? - ASP.NET Core 2.0/Razor Pages - How can I persist data in a NonFactors MVC6 grid between requests? 如何在ASP.NET MVC中的视图内部创建会话? - How can I create session inside views in asp.net mvc?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM