简体   繁体   English

使用会话变量有多安全? ASP.NET C#

[英]how safe is it to use session variables? ASP.NET C#

I have this code in my Login page: 我的登录页面中有以下代码:

        Session["user"] = user.Text;
        cmd.Parameters.AddWithValue("@user", Session["user"]);
        reader = cmd.ExecuteReader();

I saw this link how safe is it to use session variables - asp.net / c# 我看到此链接使用会话变量有多安全-ASP.NET / C#

and I want to know if I need to change this type of login. 我想知道是否需要更改这种登录类型。

my question is if its safe to use session and if its possible to steal a session from another user and enter to the website as that user or something like that. 我的问题是,会话是否可以安全使用,是否有可能从其他用户那里窃取会话并以该用户身份或类似身份进入网站。

I tried to use membership but I couldn't change the register so I moved to Session. 我尝试使用成员身份,但无法更改注册,所以我转到了Session。

Using session state to keep track of current login user is OK as long as you are on HTTPS . 只要使用HTTPS,就可以使用会话状态跟踪当前登录用户。 Session variables are stored in Server Memory (by default) . 会话变量存储在服务器内存中(默认情况下)

We all used the similar approach in Classics ASP and ASP.Net 1.0 (before Membership in ASP.Net 2.0) . 我们都在Classics ASP和ASP.Net 1.0中使用了类似的方法(在ASP.Net 2.0中加入成员资格之前)

The main drawback is the maintenance . 主要缺点是维护 It is hard to maintain when the application has too many pages and too many users with different authorizations. 当应用程序具有太多页面和太多具有不同授权的用户时,很难维护。

As it has already been said, you should not have to worry about session security as long as you use https protocol and that your application server is safe. 正如已经说过的,只要您使用https协议并且您的应用程序服务器是安全的,就不必担心会话安全性。

But you should consider using Identity framework instead of the old Membership framework. 但是您应该考虑使用Identity框架而不是旧的Membership框架。 Since 2013 Identity is the new authentication .NET standard, allowing SSO, role provider, claims based authentication etc... 自2013年以来,身份是新的身份验证.NET标准,允许SSO,角色提供者,基于声明的身份验证等...

See http://www.asp.net/identity/overview/getting-started/introduction-to-aspnet-identity to understand why you should choose identity over membership) 请参阅http://www.asp.net/identity/overview/getting-started/introduction-to-aspnet-identity以了解为什么应该选择身份而不是成员身份)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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