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
source share