gpt4 book ai didi

cookies - Formsauthentication.SetAuthCookie 和 Session 的区别用法

转载 作者:行者123 更新时间:2023-12-02 16:34:08 25 4
gpt4 key购买 nike

我似乎找不到这个看似简单的问题的答案。

使用第一个或后者有什么区别?为什么我要使用第一个?

在 MSDNAA 上,我发现以下有关 Formsauthentication.setCookie() 的内容:

Creates an authentication ticket for the supplied user name and adds it to the cookies collection of the response, or to the URL if you are using cookieless authentication.

关于 session :

ASP.NET session state enables you to store and retrieve values for a user as the user navigates the different ASP.NET pages that make up a Web application. HTTP is a stateless protocol, meaning that your Web server treats each HTTP request for a page as an independent request; by default, the server retains no knowledge of variable values used during previous requests. As a result, building Web applications that need to maintain some cross-request state information (applications that implement shopping carts, data scrolling, and so on) can be a challenge. ASP.NET session state identifies requests received from the same browser during a limited period of time as a session, and provides the ability to persist variable values for the duration of that session.

我特别感兴趣的是,当我使用 session cookie 检查用户是否正确登录时,为什么要使用 formsauthentication.SetAuthCookie。例如:

if(Session["LoggedIn"] != null) {
...Do something here that only logged in users are allowed to do...
}

最佳答案

看来我在 asp.net 网站上找到了答案:

http://forums.asp.net/t/1587046.aspx/1#4012585

关于cookies - Formsauthentication.SetAuthCookie 和 Session 的区别用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14156995/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com