简体   繁体   中英

How to set website in IIS or web.config to keep session?

Anytime I update a file in project and I am on website i loose authentication. Session is changing or I don't know what it happens. What changes should I do?

Thi is part of webconfig

<system.web>
    <sessionState cookieless="UseCookies" mode="InProc" sqlCommandTimeout="1200" sqlConnectionString="Data Source=WINDOWS2008\SQLEXPRESS;User ID=dotnet;Password=1234" timeout="20" />
    <globalization culture="en-US" />
    <httpRuntime minFreeThreads="18" minLocalRequestFreeThreads="18" executionTimeout="1000000" maxRequestLength="1024000" requestLengthDiskThreshold="1024000" />
    <!-- <sessionState timeout="60" mode="InProc" />-->
    <!-- 
    Set compilation debug="true" to insert debugging 
    symbols into the compiled page. Because this 
    affects performance, set this value to true only 
    during development.
-->
    <compilation debug="true" targetFramework="4.0">
        <assemblies>
            <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        </assemblies>

You should use authentication by means of cookies. That way your current logged-in user will not be influenced by session drops.

Note: Actually, handling authentication correctly has lots of other benefits. Counting on the session itself has many problems, and above all it does not scale.

Read more about doing authentication right in ASP.NET here:

The application pool will restart and session state will be lost. Imagine each ASP.NET application (as defined in IIS) is a program on the desktop. Saving web.config will do something similar to closing the program and reopening it.

You can use Outproc session state management (ex:Sql Server)

http://ravisystem.wordpress.com/2007/10/21/inproc-session-state-out-proc-session-state-in-aspnet/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM