简体   繁体   中英

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 read the "OK" and then redirect the user to B. At that moment, the session object is 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."

You are talking about persisting values from one Web application to another, session state is not designed for that.

You will need to persist values to a store that is available to both applications such as ASP.Net cache or a database.

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.

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. If SQL Server, you must persist the session in a database that can be accessed by both sites.

  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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM