Is it possible to make the session persistent in ASP.Net Core? So far I can only find information about cookie expiration connected to ASP.Net Identity (which I am not using), or session idle timeout (which does not persist after the user closes the browser).
Where do I find options to make the session persistent?
ASP.NET Core Session is built on top of IDistributedCache so I guess you are looking for its persistent implementation (Redis, SQL Server etc.).
Working with a distributed cache.
Related
I have a .NET Core MVC web application that is containerized and running in Azure Kubernetes Service. The application uses .NET Core Identities for user authentication.
The problem I have is that when I scale up the application to multiple instances, user authentication becomes unreliable. I believe this is because the load balancer does not guarantee that subsequent requests from the same user session go to the same instance, and as the authentication cookies creating on one instance are not valid on another instance, the user is directed to the login page again.
With the .NET Framework I would set the machineKey in the webconfig, and so multiple instances would be using the same key for encryption.
What is the appropriate way to manage this situation with a .NET Core application?
We have an ASP.net Web Forms application running on the .NET 4.61 framework, and an Asp.NET Core application running on the same .NET 4.61 framework.
The Web Forms application uses a session cookie and SQL Server to store the session information.
Is there a way to configure the Asp.NET Core application to read and use that session data?
Thanks.
No. It is not possible to share session state between ASP.NET apps and ASP.NET Core apps. This is because of two main reasons:
ASP.NET and ASP.NET Core handle session stores differently. In ASP.NET, you had session providers, whereas in ASP.NET Core, it uses IDistributedCache for session sate. While you can use something like SQL Server for both, the mechanism of actually storing the state is not the same in each case, and therefore, one couldn't read what the other is doing.
Session data is encrypted and the mechanism of encryption in ASP.NET is different from that of ASP.NET Core. In ASP.NET, the machine key is used to encrypt/decrypt, but in ASP.NET Core, there is no concept of a machine key. Instead, ASP.NET Core uses an instance of IDataProtectionProvider to encrypt/decrypt. As a result, even if you could get both to see the same session store and be able to read it, neither would be capable of decrypting the data stored by the other.
I have asp.net Core Rc2 application. To store system setting I use IOptions mechanism which is configured like that:
services.AddOptions();
services.AddSingleton<IOptions<DocumentParameters>, DocumentParametersConfigureOptions>();
All parameters are loaded from database in DocumentParametersConfigureOption class. Thanks to this solution, all system settings can be easily injected into controllers/services and are cached on the server side (they are loaded only at the start of application).
I have also a page where settings can be modified (modified in database). I would like to know how can I reload them when user clicks save without restarting web application service.
Use in memory caching.
On load, put your configuration there. On conclusive connections/resolves, read it from there. When you update it via UI, simply invalidate the cache (i.e. using the cancellation token, see link from above) or just put it manually back in there overriding the existing value.
I would create a second set of IOptions and inject them with either AddTransient or AddScoped.
Transient services will be created every time they are requested, and scoped services will be created once per request.
Here's a link to documentation on service lifetimes.
on asp.net core 1.1 you can achieve this with IOptionsSnapshot
I am trying to use the ASP.NET 5.0 Session State middleware and i want to use it with Azure cache as the session store?
Can someone point out samples to implement this?
In ASP.NET 5 the session state system requires an implementation of IDistributedCache to be available in the service provider (via dependency injection). So, the session-state system should be usable as-is; you'll just need a Redis implementation of IDistributedCache.
The ASP.NET 5 Caching repo has a sample Redis distributed cache provider that uses Redis as the backing store.
There is also an accompanying sample app that shows direct usage of the distributed cache provider.
Plugging in Azure Cache (which is based on Redis) is left as an exercise to the reader (that's you!).
I want to use session with my silverlight4 application to store data for temporary period .
So how to use Session with silverlight4 Application?
Silverlight runs on the client. You don't mention whether you are simply looking at storing data on the clients or whether you want to implement server side session. If you want to store data on the client have a look at Isolated Storage. Silverlight uses Isolated Storage as a virtual file system to store data in a hidden folder on the client machine.
Is your Silverlight app calling WCF services hosted in IIS? If so, and as long as your WCF services opt in for ASP.NET compatibility mode, ASP.NET session is available to you. With ASP.NET session you get the ability to set expiration times, dependencies etc.