Scaling out web application through multiple instances is one of biggest advantages of azure cloud. To achieve multiple VMs support for our web-role cloud application we are implementing Azure Redis Cache. We are using RedisSessionStateProvider provider for maintaining session state. Following are the configuration settings for session management within 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 session timeout is not extending with the user's postback, suppose our user logs into the application at 10:00 AM then his session data will expire at absolute 10:20 AM. If user postbacks at 10:15 AM then session should expire at 10:35 AM but this is not happening it is expiring on 10:20 AM absolute.
Following is the code at login button's click event
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 if could let me know what needs to be done to get session timeout in sliding mode. Best Regards,
H.R Yadav