Session timeout does not shift in Azure Redis Cache Session State Provider

Scaling a web application across multiple instances is one of the biggest advantages of the azure cloud. To achieve support for multiple virtual machines for our cloud-based web role application, we implement the Azure Redis cache. We use the RedisSessionStateProvider provider to maintain session state. The following are the configuration settings for session management in the web.config file.

<authentication mode="Forms"> <forms loginUrl="~/Login" slidingExpiration="true" timeout="20" defaultUrl="~/Default" /> </authentication> <sessionState timeout="20" mode="Custom" customProvider="MySessionStateStore"> <providers> <add name="MySessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" host = "dummy.redis.cache.windows.net" port = "6380" accessKey = "dummysecretkey" ssl = "true" throwOnError = "true" retryTimeoutInMilliseconds = "5000" databaseId = "0" applicationName = "" connectionTimeoutInMilliseconds = "5000" operationTimeoutInMilliseconds = "1000" connectionString = ""/> </providers> 

Our problem is that the session timeout does not apply to the user’s postback, suppose that our user enters the application at 10:00, after which his session data expires at 10:20 in the absolute. If the user sends back at 10:15, then the session should expire at 10:35, but this does not happen, it expires 10:20 in the morning.

Below is the code when pressing the login button

  protected void Button1_Click(object sender, EventArgs e) { FormsAuthentication.SetAuthCookie(TextBox1.Text.Trim(), true); ConnectionMultiplexer connection = ConnectionMultiplexer.Connec("dummy.redis.cache.windows.net,ssl=true,password=dummysecretkey"); IDatabase cache = connection.GetDatabase(); Session["UserName"] = TextBox1.Text; Response.Redirect("Default.aspx"); } 

I would appreciate it if I let me know what needs to be done to get the session timeout in slip mode. Best wishes,

HR Yadav

+5
source share
3 answers

Thanks for reporting the issue. We have released a new version of the RedisSessionStateProvider NuGet package, which fixes the error described above.

https://www.nuget.org/packages/Microsoft.Web.RedisSessionStateProvider/1.5.0

EDIT: We found another problem with this. ASP.NET does not call ResetItemTimeout for AJAX requests and becomes the responsibility of another session state method to merge the session timeout. We fixed this error and released a new NuGet package: https://www.nuget.org/packages/Microsoft.Web.RedisSessionStateProvider/1.6.5

Let us know if this solves your problem or not.

+3
source

I solved the issue of slip expiration including the following lines in global.ascx.cs

 protected void Application_AcquireRequestState() { if (HttpContext.Current.Session != null) { RedisSessionStateProvider redis = new RedisSessionStateProvider(); redis.ResetItemTimeout(HttpContext.Current, HttpContext.Current.Session.SessionID); } } 
+2
source

You must reset the key yourself (after downloading it):

 bool KeyExpire(RedisKey key, DateTime? expiry, CommandFlags flags = CommandFlags.None); bool KeyExpire(RedisKey key, TimeSpan? expiry, CommandFlags flags = CommandFlags.None); 
0
source

Source: https://habr.com/ru/post/1212503/


All Articles