Azure虚拟机未保留登录用户会话

时间:2022-03-06 13:01:52

I am developing a MVC4 application . We have hosted our application on Windows Azure IAAS Model . Right now we have configured 2 virtual machines and everything is working good. But we have an issue with maintaining User Loging .

我正在开发一个MVC4应用程序。我们在Windows Azure IAAS Model上托管了我们的应用程序。现在我们配置了2台虚拟机,一切正常。但我们在维护用户登录方面存在问题。

If i login in virtual machine 1 , its not getting carried over ,when the next request is coming from Virtual machine 2 . We have mapped two virtual machines over load balance .

如果我在虚拟机1中登录,则当下一个请求来自虚拟机2时,它不会被转移。我们已经在负载平衡上映射了两个虚拟机。

Should i look into Cache solutions . Any input will be greatly helpful ...

我应该研究一下Cache解决方案。任何输入都会非常有用......

Thanks, Jaswanth

2 个解决方案

#1


0  

You're hitting two completely separate VMs (yes load balanced, but separate). This mandates the need for storing any type of session data external to the VMs (or you need to sync the session content and have it identical in both VMs).

你正在击中两个完全独立的虚拟机(是负载平衡的,但是是分开的)。这要求存储VM外部的任何类型的会话数据(或者您需要同步会话内容并使其在两个VM中都相同)。

Azure doesn't do anything to sync session data for you. That's on you, to build it into your app's architecture. You mentioned caching, which is certainly a viable solution (which you pick, though, is up to you). There are other solutions too such as database-based session storage. Again, that's up to you.

Azure不会为您同步会话数据。这就是你,将它构建到你的应用程序架构中。你提到了缓存,这当然是一个可行的解决方案(你选择,但由你决定)。还有其他解决方案,例如基于数据库的会话存储。再一次,这取决于你。

But bottom line: If you're going to scale an app beyond a single server (VM in this case), in a load-balanced way, you cannot store session data in a specific vm.

但最重要的是:如果您要将应用程序扩展到单个服务器(在这种情况下为VM)之外,则以负载平衡的方式,您无法将会话数据存储在特定的vm中。

#2


-1  

Use a durable session state store (like Redis or SQL Server, etc) or put your state in a cookie and read/write it on each request. If cookie includes sensitive content, encrypt it.

使用持久的会话状态存储(如Redis或SQL Server等)或将您的状态放在cookie中并在每个请求上读/写它。如果cookie包含敏感内容,请对其进行加密。

#1


0  

You're hitting two completely separate VMs (yes load balanced, but separate). This mandates the need for storing any type of session data external to the VMs (or you need to sync the session content and have it identical in both VMs).

你正在击中两个完全独立的虚拟机(是负载平衡的,但是是分开的)。这要求存储VM外部的任何类型的会话数据(或者您需要同步会话内容并使其在两个VM中都相同)。

Azure doesn't do anything to sync session data for you. That's on you, to build it into your app's architecture. You mentioned caching, which is certainly a viable solution (which you pick, though, is up to you). There are other solutions too such as database-based session storage. Again, that's up to you.

Azure不会为您同步会话数据。这就是你,将它构建到你的应用程序架构中。你提到了缓存,这当然是一个可行的解决方案(你选择,但由你决定)。还有其他解决方案,例如基于数据库的会话存储。再一次,这取决于你。

But bottom line: If you're going to scale an app beyond a single server (VM in this case), in a load-balanced way, you cannot store session data in a specific vm.

但最重要的是:如果您要将应用程序扩展到单个服务器(在这种情况下为VM)之外,则以负载平衡的方式,您无法将会话数据存储在特定的vm中。

#2


-1  

Use a durable session state store (like Redis or SQL Server, etc) or put your state in a cookie and read/write it on each request. If cookie includes sensitive content, encrypt it.

使用持久的会话状态存储(如Redis或SQL Server等)或将您的状态放在cookie中并在每个请求上读/写它。如果cookie包含敏感内容,请对其进行加密。