{"id":74,"date":"2014-05-22T21:38:00","date_gmt":"2014-05-22T20:38:00","guid":{"rendered":"https:\/\/debuggersspace.com\/index.php\/2014\/05\/22\/what-are-session-state-modes-in-asp-net\/"},"modified":"2014-05-22T21:38:00","modified_gmt":"2014-05-22T20:38:00","slug":"what-are-session-state-modes-in-asp-net","status":"publish","type":"post","link":"https:\/\/debuggersspace.com\/index.php\/2014\/05\/22\/what-are-session-state-modes-in-asp-net\/","title":{"rendered":"What are Session state modes in ASP.NET?"},"content":{"rendered":"<div class='booster-block booster-read-block'>\n                <div class=\"twp-read-time\">\n                \t<i class=\"booster-icon twp-clock\"><\/i> <span>Read Time:<\/span>4 Minute, 11 Second                <\/div>\n\n            <\/div><div dir=\"ltr\" style=\"text-align: left;\">\n<div style=\"background-color: white; color: #111111;\">\n<span style=\"font-family: Arial, Helvetica, sans-serif;\">ASP.NET supports different session state storage options:<\/span><\/div>\n<ul style=\"background-color: white; border: 0px; color: #111111; margin: 10px 0px; padding: 0px 0px 0px 40px;\">\n<li style=\"border: 0px; margin: 0px; padding: 0px;\"><span style=\"font-family: Arial, Helvetica, sans-serif;\"><strong style=\"border: 0px; margin: 0px; padding: 0px;\">In-Process<\/strong>&nbsp;is the default approach. It stores session state locally on same web server memory where the application is running.<\/span><\/li>\n<li style=\"border: 0px; margin: 0px; padding: 0px;\"><span style=\"font-family: Arial, Helvetica, sans-serif;\"><strong style=\"border: 0px; margin: 0px; padding: 0px;\">StateServer<\/strong>&nbsp;mode stores session state in a process other than the one where application is running. Naturally, it has added advantages that session state is accessible from multiple web servers in a Web Farm and also session state will remain preserved even web application is restarted.<\/span><\/li>\n<li style=\"border: 0px; margin: 0px; padding: 0px;\"><span style=\"font-family: Arial, Helvetica, sans-serif;\"><strong style=\"border: 0px; margin: 0px; padding: 0px;\">SQLServer<\/strong>&nbsp;mode stores session state in SQL Server database. It has the same advantages as that of StateServer.<\/span><\/li>\n<li style=\"border: 0px; margin: 0px; padding: 0px;\"><span style=\"font-family: Arial, Helvetica, sans-serif;\"><strong style=\"border: 0px; margin: 0px; padding: 0px;\">Custom<\/strong>&nbsp;modes allows to define our custom storage provider.<\/span><\/li>\n<li style=\"border: 0px; margin: 0px; padding: 0px;\"><span style=\"font-family: Arial, Helvetica, sans-serif;\"><strong style=\"border: 0px; margin: 0px; padding: 0px;\">Off<\/strong>&nbsp;mode disables session storage.<\/span><\/li>\n<\/ul>\n<div>\n<span style=\"color: #111111; font-family: Arial, Helvetica, sans-serif;\">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/span><\/div>\n<div>\n<span style=\"color: #111111; font-family: Arial, Helvetica, sans-serif;\"><br \/><\/span><\/div>\n<div>\n<h5 style=\"background-color: white; margin-bottom: 2px;\">\n<span style=\"font-family: Arial, Helvetica, sans-serif; font-size: small;\">Session State Service<\/span><\/h5>\n<div>\n<span style=\"font-family: Arial, Helvetica, sans-serif; font-size: small;\"><br \/><\/span><\/div>\n<div style=\"background-color: white; color: #111111;\">\n<span style=\"font-family: Arial, Helvetica, sans-serif;\">As an alternative to using in-process storage for session state, ASP.NET provides the ASP.NET State Service. The State Service gives you an out-of-process alternative for storing session state that is not tied quite so closely to ASP. NET&#8217;s own process.<\/span><\/div>\n<div style=\"background-color: white; color: #111111;\">\n<span style=\"font-family: Arial, Helvetica, sans-serif;\">To use the State Service, you need to edit the&nbsp;<code style=\"border: 0px; color: #990000; margin: 0px; padding: 0px;\">sessionState&nbsp;<\/code>element in your ASP.NET application\u2019s&nbsp;<em style=\"border: 0px; margin: 0px; padding: 0px;\">web.config<\/em>&nbsp;file:<\/span><\/div>\n<div style=\"background-color: white; color: #111111;\">\n<span style=\"font-family: Arial, Helvetica, sans-serif;\">You\u2019ll also need to start the ASP.NET State Service on the computer that you specified in the<code style=\"border: 0px; color: #990000; margin: 0px; padding: 0px;\">stateConnectionString&nbsp;<\/code>attribute. The .NET Framework installs this service, but by default it\u2019s set to manual startup. If you\u2019re going to depend on it for storing session state, you\u2019ll want to change that to automatic startup by using the Services MMC plug-in in the Administrative Tools group.<\/span><\/div>\n<div style=\"background-color: white; color: #111111;\">\n<span style=\"font-family: Arial, Helvetica, sans-serif;\">If you make these changes, and then repeat the previous set of steps, you\u2019ll see slightly different behavior: session state persists even if you recycle the ASP.NET process.<\/span><\/div>\n<div style=\"background-color: white; color: #111111;\">\n<span style=\"font-family: Arial, Helvetica, sans-serif;\">There are two main advantages to using the State Service. First, it is not running in the same process as ASP.NET, so a crash of ASP.NET will not destroy session information. Second, the&nbsp;<code style=\"border: 0px; color: #990000; margin: 0px; padding: 0px;\">stateConnectionString&nbsp;<\/code>that\u2019s used to locate the State Service includes the TCP\/IP address of the service, which need not be running on the same computer as ASP.NET. This allows you to share state information across a web garden (multiple processors on the same computer) or even across a web farm (multiple servers running the application). With the default in-process storage, you can\u2019t share state information between multiple instances of your application.<\/span><\/div>\n<div style=\"background-color: white; color: #111111;\">\n<span style=\"font-family: Arial, Helvetica, sans-serif;\">The major disadvantage of using the State Service is that it\u2019s an external process, rather than part of ASP.NET. That means that reading and writing session state is slower than it would be if you kept the state in-process. And, of course, it\u2019s one more process that you need to manage. As an example of the extra effort that this can entail, there is a bug in the initial release of the State Service that allows a determined attacker to crash the ASP.NET process remotely. If you\u2019re using the State Service to store session state, you should install the patch from Microsoft Security Bulletin MS02-66, or install SP2 for the .NET Framework.<\/span><\/div>\n<h3 style=\"background-color: white;\">\n<span style=\"font-family: Arial, Helvetica, sans-serif; font-size: small;\">Microsoft SQL Server<\/span><\/h3>\n<div style=\"background-color: white; color: #111111;\">\n<span style=\"font-family: Arial, Helvetica, sans-serif;\">The final choice for storing state information is to save it in a Microsoft SQL Server database. To use SQL Server for storing session state, you need to perform several setup steps:<\/span><\/div>\n<div style=\"background-color: white; color: #111111;\">\n<span style=\"font-family: Arial, Helvetica, sans-serif;\">Run the&nbsp;<em style=\"border: 0px; margin: 0px; padding: 0px;\">InstallSqlState.sql<\/em>&nbsp;script on the Microsoft SQL Server where you intend to store session state. This script will create the necessary database and database objects. The .NET Framework installs this script in the same folder as its compilers and other tools\u2013for example,&nbsp;<em style=\"border: 0px; margin: 0px; padding: 0px;\">C:WINNTMicrosoft.NETFrameworkv1.0.3705<\/em>&nbsp;on a Windows 2000 computer with the 1.0 version of the Framework. Edit the&nbsp;<code style=\"border: 0px; color: #990000; margin: 0px; padding: 0px;\">sessionState&nbsp;<\/code>element in the&nbsp;<em style=\"border: 0px; margin: 0px; padding: 0px;\">web.config<\/em>&nbsp;file for your ASP.NET application as follows:<\/span><\/div>\n<div style=\"background-color: white; color: #111111;\">\n<span style=\"font-family: Arial, Helvetica, sans-serif;\">Supply the server name, user name, and password for a SQL Server account that has access to the session state database in the&nbsp;<code style=\"border: 0px; color: #990000; margin: 0px; padding: 0px;\">sqlConnectionString&nbsp;<\/code>attribute.<\/span><\/div>\n<div style=\"background-color: white; color: #111111;\">\n<span style=\"font-family: Arial, Helvetica, sans-serif;\">Like the State Service, SQL Server lets you share session state among the processors in a web garden or the servers in a web farm. But you also get the additional benefit of persistent storage. Even if the computer hosting SQL Server crashes and is restarted, the session state information will still be present in the database, and will be available as soon as the database is running again. That\u2019s because SQL Server, being an industrial-strength database, is designed to log its operations and protect your data at (almost) all costs. If you\u2019re willing to invest in SQL Server clustering, you can keep the session state data available transparently to ASP.NET even if the primary SQL Server computer crashes.<\/span><\/div>\n<div style=\"background-color: white; color: #111111;\">\n<span style=\"font-family: Arial, Helvetica, sans-serif;\">Like the State Service, SQL Server is slower than keeping session state in process. You also need to pay additional licensing fees to use SQL Server for session state in a production application. And, of course, you need to worry about SQL Server-specific threats such as the \u201cSlammer\u201d worm.<\/span><\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>ASP.NET supports different session state storage options: In-Process&nbsp;is the default approach. It stores session state locally on same web server memory where the application is running. StateServer&nbsp;mode stores session state in a process other than the one where application is running. Naturally, it has added advantages that session state is accessible from multiple web servers [&hellip;]<\/p>\n","protected":false},"author":43,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","footnotes":""},"categories":[23],"tags":[],"class_list":["post-74","post","type-post","status-publish","format-standard","hentry","category-asp-net"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Himanshu Namdeo","author_link":"https:\/\/debuggersspace.com\/author\/admin\/"},"uagb_comment_info":0,"uagb_excerpt":"ASP.NET supports different session state storage options: In-Process&nbsp;is the default approach. It stores session state locally on same web server memory where the application is running. StateServer&nbsp;mode stores session state in a process other than the one where application is running. Naturally, it has added advantages that session state is accessible from multiple web servers&hellip;","_links":{"self":[{"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/posts\/74"}],"collection":[{"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/users\/43"}],"replies":[{"embeddable":true,"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/comments?post=74"}],"version-history":[{"count":0,"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/posts\/74\/revisions"}],"wp:attachment":[{"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/media?parent=74"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/categories?post=74"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/tags?post=74"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}