Can AppFabricCacheSessionStoreProvider and StateServer co-exist within a same application? - c#

There are some systems within a .NET project I'm working on which use StateServer. We're now using Appfabric cache for caching some stuff which we get from DB. Can these two co exist in the same config file?
The session state part of my Config file looks like this
<sessionState mode="StateServer" cookieless="true" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" regenerateExpiredSessionId="true" timeout="30" stateNetworkTimeout="30"/>
<sessionState mode="Custom" customProvider="AppFabricCacheSessionStoreProvider">
<providers>
<!-- specify the named cache for session data -->
<add name="AppFabricCacheSessionStoreProvider" type="Microsoft.ApplicationServer.Caching.DataCacheSessionStoreProvider" cacheName="default" />
</providers>
</sessionState>
Obviously, this throws an error that session state is already defined and that i cant re-define it.
Till we replace StateServer systems with Appfabric Caching systems ,which will take some time for us (its a very big project), we dont want to disturb the existing systems. Hence this question.

No, you can only have one unique active session state provider at the same time and it is also not possible to dynamically change at runtime.
In past, I also investigated this article in order to create a session store wrapper. Finally, I gave up because of complexity and poor performance.

Related

Building Sitecore connection strings in c#

I am currently working on a Sitecore project where the same sitecore webapplication would point to Sitecore databases based on witch IIS website name the webapplication is running under.
Let’s say the IIS webapplication is called www.company1.com, then the database names would be: www.company1.com.master, www.company1.com.web in \App_Config\ConnectionStrings.config.
I have tried to modify the connection string on Application_Start(), but that is not the best solution (possible but slow and ugly, first request dropped etc.).
Another approach is to use config file transformations, but that is not an options based on the number of web sites.
Is it possible to modify Sitecore.Context, somewhere in Application_Start – so Sitecore.Context.Database would work as expected?
You could setup multiple connection strings entries and then reference it in the node in your web.config.
<connectionStrings>
<add name="core" connectionString="[connection_string]" />
<add name="master" connectionString="[connection_string]" />
<add name="web" connectionString="[connection_string]" />
<add name="web1" connectionString="[connection_string]" />
<add name="web2" connectionString="[connection_string]" />
</connectionStrings>
<sites>
<site name="website1" database="web1" hostName="www.company1.com" (...) />
<site name="website2" database="web2" hostName="www.company2.com" (...) />
</sites>
Would that work for you?
I don't think there is. But you would not want to change the actual name of the connection string, you would want to change the value produced by it. Changing the standard Sitecore connection string names ("master", "core" and "web") would require a lot of related changes in web.config and related config files. On top of that you would probably end up in trouble, as there are modules and code out there still - doing specific Factory.GetDatabase("master") API calls - even if they shouldn't.
I've never attempted what you're asking for here in a Sitecore solution, but I expect it should be possible to create your own ConnectionStringProvider, as described in http://msdn.microsoft.com/en-us/library/vstudio/ms254494(v=vs.100).aspx
The provider would need to return proper results for "master", "core" and so on - any databases you would normally have defined in your solution - and then a dynamic connection string based on the pattern you describe; considering the IIS application name or whatever you need.

Asp.net session timeouts

Can anyone tell me why the session clears itself automatically after a certain amount of time in my application?
I use the following line to create a session variable to pass data between classes:
string data = TextBox.Text
Session["Data"] = data;
After around 10 - 15 minutes i refresh the page to find that the session cache has been cleared and my application collapses on itself.
Is there a way to extend the session time in web.config?
Im not fully aware of how powerful Session's can be so any help would be great guys thanks
Look in your web.config file and see the sessionState section:
<configuration>
<system.web>
<sessionState timeout="30"></sessionState>
</system.web>
</configuration>
I have changed it to 30 to extend the Sessions life for an additional 15minutes. You can change this to suit your requirements.

Sessions stored in a co-located Azure cache gets out of sync on multiple instances

For my MVC4 application, run in Azure, I store the sessions in a co-located cache. As described in this How-to that Microsoft provide.
I run two small instances, and everything seems to work fine. I can log in to the application, and I remain logged in when I browse around within the application. So the session seem to work on both instances.
However, when I update the session data something like this:
HttpContext.Current.Session["someVar"] = "new value";
That change only seem to have an effect on the instance that handle that particular request. Now as I browse around the application, sometimes I get the initial value and sometimes I get the updated value.
I haven't made any changes to the web.config, so it looks exactly as it do when it gets added by the Nuget package:
<sessionState mode="Custom" customProvider="AppFabricCacheSessionStoreProvider">
<providers>
<add name="AppFabricCacheSessionStoreProvider"
type="Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider, Microsoft.Web.DistributedCache"
cacheName="default"
useBlobMode="true"
dataCacheClientName="default" />
</providers>
</sessionState>
Do I need to handle sessions in another way when using the Azure cache, or is it something else I'm missing here?
You need to assign an applicationName so that the distributed cache can view the shared state within the same application boundary. See MSDN forum post for reference.
<add name="AppFabricCacheSessionStoreProvider"
type="Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider, Microsoft.Web.DistributedCache"
applicationName="azureMVC4App"
cacheName="default"
useBlobMode="true"
dataCacheClientName="default" />
If you want to share cache state across application boundaries, you need to assign sharedId

asp.net Session timeout issue

got a problem with my asp.net mvc project timing out after only a couple of minutes. It's especially annoying because I've got quite a complex upload and import procedure which falls over when i get logged out. I currently use asp.net membership provider for authentication.
I've tried a few things that I've seen on this site and others but to no avail. Here is what I have so far in the web config:
<location path="Admin/Upload">
<system.web>
<httpRuntime executionTimeout="1200"/>
</system.web>
</location>
<system.web>
<sessionState mode="InProc" timeout="20" cookieless="false" />
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="20" />
</authentication>
<add name="ConnectionString" providerName="System.Data.SqlClient" connectionString="Server=SERVERNAME;Database=DBNAME;User Id=USER;Password=PASSWORD;timeout=30;MultipleActiveResultSets=True" />
I was sure it was only a minute before being timed out before I added the sessionstate timeout, then it was upped to 2 mins, but can't be 100%.
I thought about using this:
<lifetime leaseTime="15M"/>
...but not 100% sure how to implement it - anyone had any success with it, or know something else I could try?
Thanks
EDIT: I'm on a cloud hosting solution, but only have a control panel - no access to IIS
UPDATE: I've now tried adding lifetime leasetime and it's not made any difference:
<system.runtime.remoting>
<application>
<lifetime leaseTime="20M" />
</application>
</system.runtime.remoting>
</configuration>
UPDATE 2:
Ok, I've edited the title and the web config values to reflect my latest effort, but I'm still struggling. I spoke to the hosting company who set the connection timeout to 20 minutes. However, it the session ends after 10 mins. Is there anything else I can try?
I'm getting there, but I would like 20 minutes!
The lifetime leasetime tag goes in the application tag.
<application>
<lifetime leasetime = "15M"/>
I've never actually used it but if it is like other timeouts idk if you will need the M at the end. That is pure speculation though. You should also be able to set it to "0" so that its lifetime is "forever"
As for the session timeout that looks like it should be set for 100 minutes. However, it should be inside of your <configuration> tags
EDIT
Completely unrelated to the question kind of. But i like how your runtime execution timeout is "over 9000"
Right, I got a solution to this, but it wasn't what I was expecting.
It turned out I was using the aspnet Membership Provider wrongly. I was using like a previous membership system I worked on and logging in then setting the UserId as a session variable and using that throughout the site. I then discovered that is the incorrect way to use it, and changed it to a combination of User.Identity.IsAuthenticated and Membership.GetUser().ProviderUserKey.
It no longer times out and all is well. Thanks anyway.

DotNetOpenAuth ASP.NET MVC 3 Session Issue

I am using the openid-selector with DotNetOpenAuth in my MVC 3 app. Whenever I set a session variable and the DotNetOpenAuth sections are in the web.config, my session variables don't stick after a redirect.
I checked the Session.SessionID variable and it is still the same, so I am in the same session (I believe), but when I check the session variables I just set after a redirect they are all set to null.
I haven't seen anyone else with this issue. I am wondering if DotNetOpenAuth just isn't ready for MVC 3 yet. I am using the latest version of DotNetOpenAuth as well.
Here are the relevant portions of the web.config if it helps:
<configSections>
<section name="uri" type="System.Configuration.UriSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<section name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection" requirePermission="false" allowLocation="true"/>
</configSections>
<uri>
<idn enabled="All"/>
<iriParsing enabled="true"/>
</uri>
<system.net>
<defaultProxy enabled="true"/>
<settings>
<servicePointManager checkCertificateRevocationList="true"/>
</settings>
</system.net>
<dotNetOpenAuth>
<openid>
<relyingParty>
<security requireSsl="false"/>
<behaviors>
<add type="DotNetOpenAuth.OpenId.Behaviors.AXFetchAsSregTransform, DotNetOpenAuth"/>
</behaviors>
</relyingParty>
</openid>
<messaging>
<untrustedWebRequest>
<whitelistHosts>
<add name="localhost"/>
</whitelistHosts>
</untrustedWebRequest>
</messaging>
<reporting enabled="true"/>
</dotNetOpenAuth>
Updated:
it is happening on my development server, either in IIS, or when I run the ASP.NET development server.
Also, I tried running session in process and out of process using the state server, and it didn't make a difference.
In regards to a new session, I checked the session_start event, and that isn't being called. I also checked the Session.IsNewSession, and that returned false as well. So something is randomly (or maybe not so randomly) deleting my session variables!
Not the best answer, but I figured out that it's the response.redirect that is killing the session variables for some reason.
So I just made it do a javascript redirect instead, the session stays, everything works fine. Still really don't know what the real issue is here, but hey, I don't have all day to figure it out.
Found the issue here (long ago now). Apparently MVC2 didn't care if I had a view for my actions where I just did some processing then a redirect.
However starting in MVC3, after my upgrade, if I didn't have a view for my action, the page registered an error, and once there was an error, the framework did not store the session variables I just set.
So simple fix... add the views and then also make sure there are no errors in the views.
This should work. I have used DotNetOpenAuth with ASP.NET MVC 3 without any issues. You might want to check that your session doesn't expire during the user is on the remote site for authentication. The fact that you are getting the same SessionId doesn't mean that the session hasn't expired. This could also happen if the server restarts the AppDomain.
DotNetOpenAuth certainly doesn't have Session.Abandon or Session.Clear anywhere in its codebase. It seems possible that if you're setting cookies after the redirect has been sent to the client that those cookies would be lost. Session variables aren't typically persisted as cookies individually though, so if you session cookie made it (and apparently it seems to have) then the rest of your state ought to be there.
It would be interesting to dig into this by implementing your own session store and monitoring what's really going on.

Categories

Resources