What would happen if you try to assign a string to this integer variable? Well, like everything else in a statically typed language, you will get an exception.Īm I missing anything here? I simply can't understand why such a design decision has been made by the Asp.net development team and how the developer could benefit from that. ![]() Second, if we assume that the session variables also has to be statically typed, then is it "technically" possible to implement Asp.net's session in a way that when you define a session variable like below, the compiler allocates the memory in the heap, keep the data type next to it and simply eliminates the need for casting it each time? Session = 0 // integer type, available at compile-time What I'm thinking is, first, why you need to have such a feature only for the session, in a statically typed language like Asp.net/C#? For example, what is the use case of defining a "session" variable as an integer, but then put string on it at the run-time? Is there any practical use case and requirement for such a feature, not only in Asp.net but any other language? As my colleagues say, that's because you can basically have a dynamically typed session object, at run-time. I'm not sure if that's the case or not or even if I have understood it properly, but what I don't understand is why it has to be implemented in a way that the developer has to cast it before using it. Session = ((int)Session) + 1 // it works hereĪsking my C# developer colleagues, it seems that the Session is somehow an object that covers up the actual data type of the variable, apparently without losing it, but for some reason you still need to cast it anyway any time you want to access it. Session = Session + 1 // throws exception When working with the session, regardless of the data type that I was specifying for the session variable, I had to cast the session variable any time I needed to access it. They will guide you through and make you understand the things about the same.I'm not a Asp.net/C# developer myself but recently had to slightly refactor a Asp.net/C# project and I had to use Session at some point. ![]() If you have any doubt about NCache or asp.net core application, you can anytime get in touch with the field professionals. net, which makes it perfect fit for your asp.net core application. When you work with NCache, you will find that it is not just fast but scalable too. You can also avail several benefits from such configuration, such as. There is no need to write lengthy code snippets- it can be easily achieved with simple codes. There is minimum coding required for configuring NCache session provider for asp.net core apps. Once the configuration of NCache for storing sessions is done successfully, you can simply use it with your asp.net core app for Read and Write purposes or operations. Services.AddNCacheDistributedCache(configuration =>Ĭonfiguration.CacheName = "myDistributedCache" ![]() Public void ConfigureServices(IServiceCollection services) ![]() Here is the reference code to explain configuration of distributed cache provider in the startup.cs class of the asp.net core app. NCache lets you to do that by either organizing all settings in Startup.cs class or simply by reading them via AppSettings.json file within the asp.net core applications. To configure session provider for distributed cache, you don’t need much programming effort.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |