2013-12-11 38 views
0

當我的站點處於空閒狀態時,我想在asp.net中自動註銷我的站點。 我使用身份驗證在web.config中將sessiontimeout設置爲「10分鐘」。 例如:如果我的網站處於閒置狀態9分鐘,然後我使用mysite(即,使我的網站非活動模式爲活動模式)。然後,計時器將不得不從新會話開始(例如它必須以0:0:0開始)。 如果我的會話超時(即超過10分鐘)網站將不得不自動註銷.. 請指導我?? 任何想法????如何在asp.net中10分鐘後自動註銷我的網站,在我的網站處於閒置狀態?

回答

0

您可以使用表單身份驗證併爲您的目的設置會話超時。

<configuration> 
    <system.web> 
    <sessionState timeout="10"></sessionState> 
    </system.web> 
</configuration> 

這將使會話時間超出10分鐘。如果任何請求在10分鐘之前到來,那麼它將再次增加(總共10分鐘)。

更多詳細信息
How to set session timeout in web.config

您可以使用slidingExpiration="false"在你的web.config文件,如果你只婉10分鐘。

More details

根據MSDN

When the SlidingExpiration is set to true, the time interval during which the authentication 
cookie is valid is reset to the expiration Timeout property value. This happens if the user 
browses after half of the timeout has expired. For example, if you set an expiration of 20 
minutes by using sliding expiration, a user can visit the site at 2:00 PM and receive a cookie 
that is set to expire at 2:20 PM. The expiration is only updated if the user visits the site 
after 2:10 PM. If the user visits the site at 2:09 PM, the cookie is not updated because half 
of the expiration time has not passed. If the user then waits 12 minutes, visiting the site at 
2:21 PM, the cookie will be expired. 
0

很難明白你正在嘗試做的。爲什麼這個問題用「javascript」和「ajax」標記?

會話狀態不一定涉及表單身份驗證。我本可以從您的網站發佈一個持久性Cookie,並且無論您的網站保持閒置狀態的時間長短都沒有關係,我仍然可以向您的網站發送經過身份驗證的請求...因爲我擁有持久性Cookie。更重要的是,您甚至可以重新啓動網站或您的應用程序池...我仍然不會從您的網站註銷。

如果你想閒置10分鐘後註銷用戶您的網站和您使用窗體身份驗證,然後提出你的使用者,並在10分鐘後過期餅乾,見下文

<forms 
    timeout="10"> 
</forms> 
例如WEB.CONFIG

如果你想「重置」過期值,然後使用在web.config中滑動過期這樣

<forms  
    timeout="10" 
    slidingExpiration="true"> 
</forms> 

您可以指定窗體身份驗證有更多的價值。閱讀MSDN文檔...

http://msdn.microsoft.com/en-us/library/1d3t3c61(v=vs.85).aspx

我覺得你是一個有點糊塗。希望這個答案讓事情更清楚一點我對你的朋友

利奧

+0

我明白謝謝 – PremKumar