Devexpress 响应式Web应用程序模板用户/注册实现asp.net Web表单
您好,我是一名初级开发人员。我需要一些我正在使用的信息 我无法实现web表单安全性这是我的类详细信息Devexpress 响应式Web应用程序模板用户/注册实现asp.net Web表单,devexpress,Devexpress,您好,我是一名初级开发人员。我需要一些我正在使用的信息 我无法实现web表单安全性这是我的类详细信息 using System.Web; namespace SECODMS.Model { public class ApplicationUser { public string UserName { get ; set; } public string FirstName{ get; set; } public string LastName { ge
using System.Web;
namespace SECODMS.Model {
public class ApplicationUser {
public string UserName { get ; set; }
public string FirstName{ get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string AvatarUrl { get; set; }
}
public static class AuthHelper {
public static bool SignIn(string userName, string password) {
HttpContext.Current.Session["User"] = GetLoggedInUserInfo();
return true;
}
public static void SignOut() {
HttpContext.Current.Session["User"] = null;
}
public static bool IsAuthenticated() {
return GetLoggedInUserInfo() != null;
}
public static ApplicationUser GetLoggedInUserInfo()
{
return HttpContext.Current.Session["User"] as ApplicationUser;
}
private static ApplicationUser CreateDefualtUser() {
return new ApplicationUser {
UserName ="vvnbnbnb",
FirstName = "Julia",
LastName = "Bell",
Email = "julia.bell@example.com",
AvatarUrl = "~/Content/Photo/Julia_Bell.jpg"
};
}
}
}
这是我的签名页代码
如何实现基于用户的web表单安全
这是我的第一篇帖子,如果有任何错误,请提前道歉。在设置会话的代码中,您使用的是
Session[“user”]=UserNameTextBox代码>
这是错误的,因为您必须创建应用程序用户的实例,然后将其设置为“user”
键的值。在GetLoggedInUserInfo()
中,您将从会话中获取值,然后转换为ApplicationUser
。当强制转换失败时,这将始终返回null
修复会话初始化,登录流将正常工作