Tag: 会话

如何在cookie中存储对象?

虽然这在C#中是可能的:(在这种情况下,User是一个L2S类) User user = // function to get user Session[“User”] = user; 为什么这不可能? User user = // function to get user HttpCookie cookie = new HttpCookie(); cookie.Value = user; 怎么能这样呢? 我不想将用户的id存储在cookie中,然后进行一些validation。 顺便说一句,如果可能的话,将对象存储在cookie中而不仅仅是ID是安全的吗?

静态会话类和多个用户

我正在构建一个类来在会话中存储用户ID和用户角色。 我不确定当多个用户同时在网站上时这个类会如何表现。 有没有人看到这个问题? public static class SessionHandler { //*** Session String Values *********************** private static string _userID = “UserID”; private static string _userRole = “UserRole”; //*** Sets and Gets ********************************************************** public static string UserID { get { if (HttpContext.Current.Session[SessionHandler._userID] == null) { return string.Empty; } else { return HttpContext.Current.Session[SessionHandler._userID].ToString(); } } set { HttpContext.Current.Session[SessionHandler._userID] = […]

使用会话状态是一种不安全的方式来在asp.net中创建用户登录和角色

考虑一个设置,其中id和密码列表存储在服务器上的数据库中,当用户输入他的登录凭据时,代码隐藏对服务器validation它并设置诸如Session [“id”] Session [“login”之类的值“]确定用户是否有权访问某个页面。 当用户尝试浏览页面时,页面会查看会话变量,然后根据需要重新定位用户并相应地调整其页面上的按钮。 这种设置有多安全。 asp.net的内置登录和角色function似乎过于严格,所以我试图探索其他选项。

必须声明标量变量“@Email”

我正在尝试将值从数据库表传递到几个标签,其中电子邮件列与输入的电子邮件匹配。我已经使用会话将登录页面中输入的电子邮件传递到此页面。像这样: protected void btnLogin_Click(object sender, EventArgs e) { if (AuthenticateUser(txtEmail.Text, txtPassword.Text)) { FormsAuthentication.RedirectFromLoginPage(txtEmail.Text, chkBoxRememberMe.Checked); Session[“Email”] = txtEmail.Text; Response.Redirect(“~/Account.aspx”); } 然后我将会话值传递给ACOUNTS页面上的lblEmail。然后我试图从数据库tabel中检索值’Name’和’Balance’,其中Emails匹配表中的那个。像这样: protected void Page_Load(object sender, EventArgs e) { lblEmail.Text = Session[“Email”].ToString(); string CS = ConfigurationManager.ConnectionStrings[“ABCD”].ConnectionString; using (SqlConnection con = new SqlConnection(CS)) { SqlCommand cmd = new SqlCommand(“Select * from tblRegister where @Email = ” + lblEmail.Text, […]

会话安全存储登录名和密码哈希吗?

为Intranet应用程序存储用户名和SHA1登录的最佳方法是什么? 会话相对安全的方式来保存多域信息,用户名和密码哈希等信息吗? 我将它们保存为Session[“data”] = customObject() 我是否需要执行任何其他步骤才能确保这些数据安全? 是否存在可能受到危害的潜在安全问题或漏洞? 某种会话注入? 我应该使用一些私钥进程来锁定/打开会话数据以供阅读吗?

重定向时出现错误’响应在此上下文中不可用’

我使用以下代码将用户重定向到页面。 Session[“USERDATA”] = user; if (roleName.Equals(“Zerker”, StringComparison.CurrentCulture)) Response.Redirect(“~/Account/Dashboard.aspx”); 但这会导致错误。 在这种情况下无法获得响应。 我该怎么办?

C#无法检查Session是否存在?

当我执行以下操作时出现错误: if(Session[“value”] != null) { // code } 我得到的错误是这样的: 你调用的对象是空的。 为什么是这样? 我总是这样检查我的会话? 我正在使用MVC框架,这与它有关吗? 编辑: 代码位于Controller的构造函数中: public class MyController : ControllerBase { private int mVar; public MyController() { if (Session[“value”] != null) { mVar= (int)Session[“value”]; } } }

异步线程和会话

当使用此签名生成新的异步线程时,ASP.NET会话对象是否可用于此新线程? IAsyncResult asyncCall = f.BeginInvoke(null, f);

在C#中更新对象时会话对象发生更改

我有这个非常奇怪的问题,我确信我在这里遗漏了一些明显的东西。 我有这两行: HttpContext.Current.Session[listModelType + “ListModel”] = listModel; listModel.ProductRows = new Collection(listModel.ProductRows.Where(r => r.ParentRowId == 0).ToList()); 执行第二行后,我的会话对象也会更新(根据Visual Studio中的“Watch”) 我在这里想念的是什么? 我试过了 int i = 0; HttpContext.Current.Session[“i”] = i; i++; 和HttpContext.Current.Session [“i”]保持为0。

“会话”在当前上下文中不存在

我有以下代码,使用会话但我在行中有错误: if (Session[“ShoppingCart”] == null) 错误是cS0103: The name ‘Session’ does not exist in the current context什么问题? using System; using System.Data; using System.Configuration; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Collections.Generic; using System.Web.SessionState; /// /// Summary description for ShoppingCart /// public class ShoppingCart { List list; […]