Tag: 表单身份validation

如何在其他用户更改其用户名时强制注销用户?

在我的应用程序中,我使用Forms-Authentication登录并注销用户。 一个function是管理员可以更改其他用户的用户名。 在这种情况下,我需要注销用户名已更改的用户。 如果我不这样做,由于之前设置了cookie,他们可以访问应用程序并收到错误消息(因为他们的用户名不存在,并且有些部分我使用他们的用户名来实现某些function)。 如何强制这些用户使用Forms-Authentication注销? 更新: public override void OnActionExecuting(ActionExecutingContext filterContext) { string controller = filterContext.RouteData.Values[“controller”].ToString(); string action = filterContext.RouteData.Values[“action”].ToString(); ; // Below returns the previous username, which does not exist anymore in db. string userName = HttpContext.Current.User.Identity.Name; UnitOfWork unitOfWork = new UnitOfWork(); if (!unitOfWork.UserRepository.UserExists(userName)) { FormsAuthentication.SignOut(); filterContext.HttpContext.Session.Clear(); filterContext.HttpContext.Session.Abandon(); // I am not using Roles. […]

System.Web.HttpContext.Current.User.Identity.IsAuthenticated有时会失败

我的生产网站(不是我的开发网站)遇到了问题。 有时Firefox和Chrome都无法登录用户(所有用户都在我们的客户网络和一般网络上)。 但奇怪的是,Internet Explorer始终正常工作,并且从未失败过一次(我在浏览器中删除了缓存和cookie,但仍然会发生同样的事情)。 然后经过一个小时或一段时间后,Firefox和Chrome会再次开始正常运行。 我有一个缩小到下面的function,即使在登录后总是返回false。 public bool isLoggedIn() { return System.Web.HttpContext.Current.User.Identity.IsAuthenticated; } 所以这个过程如下,用户将使用此function登录: public void Login_OnClick(object sender, EventArgs args) { string email = UserName.Text; string password = Password.Text; string errorMsg = string.Empty; bool cb = cb_agreeterms.Checked; if (tests) { // The code in here tests to see if email, password, etc. have been filled […]

EnableCrossAppRedirects – 跨域function在哪里记录?

这里有一个有趣的ASP.NET FormsAuthenticationfunction在这个SO答案中解释: 如何在app域之间传递经过身份validation的会话 快速摘要; 您可以使用相同的加密密钥创建两个ASP.NET网站。 WebsiteA可以创建一个formauth令牌,并使用查询字符串(或POST正文)中的令牌重定向到WebsiteB。 在WebsiteB和ASP.NET中启用EnableCrossAppRedirects会检测令牌并创建formauth cookie。 在代码中: FormsAuthentication.RedirectFromLoginPage(“alice”, true); FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(“Alice”, true, 30); string encrypted = FormsAuthentication.Encrypt(ticket); Response.Redirect(“http://siteb.dev/Secure/WebForm1.aspx?” + FormsAuthentication.FormsCookieName + “=” + encrypted); 听起来像一个很棒的function,但它在哪里记录? 使用未记录的function我会感到有些不安。 我看过的地方 – 在任何MSDN参考中都没有提到这个function。 我想也许RedirectFromLoginPage会像我上面的代码一样构建重定向,但事实并非如此。 EnableCrossAppRedirects – 当重定向URL未指向当前应用程序中的页面时,在RedirectFromLoginPage方法中检查“。如果EnableCrossAppRedirects为true,则执行重定向” 跨应用程序进行表单身份validation – 关于设置计算机密钥以便在子域上创建cookie的一些建议,而不是关于EnableCrossAppRedirects 表单用于身份validation

表单身份validation了解context.user.identity

由于此过程的文档非常模糊且令人困惑(或过时),我想validation我是否正确执行并且没有遗漏任何步骤。 我正在尝试创建一个安全的登录系统,在浏览器关闭时到期。 – 在我的web.config中我有以下内容 – 所以我有一个带有用户名/密码文本框的登录表单和这个按钮: 在Login_Authenticate内部我执行以下操作: protected void Login_Authenticate(object sender, EventArgs e){ string userName = UserName.Text; string password = Password.Text; bool Authenticated = false; // Here’s code that makes sure that Username and Password is CORRECT if(AuthClass.Authenticate(userName, password)){ Authenticated = true; } // error checking does happen here. if (Authenticated) { FormsAuthenticationTicket ticket = […]

如何在ASP.NET MVC中关闭浏览器或选项卡时将用户注销?

我需要在用户关闭选项卡或浏览器时注销用户,我该如何在ASP.NET MVC中执行此操作?

如何允许匿名用户访问MVC中的某个给定页面?

我在ASP.NET MVC Web应用程序中启用了表单身份validation。 我想允许匿名用户只访问某些特定页面,例如Register.cshtml。 通过这样做,我能够允许从我的根web.config访问我的CSS文件。 现在我想允许匿名访问其他页面,如Home和Register。 有人知道怎么做到这一点吗?

跨子域的表单身份validation

当身份validation发生在子域而不是父域时,是否可以跨子域validation用户? 例如: 用户登录到site1.parent.com,然后我们需要将它们发送到reporting.parent.com。 即使在子域中发生登录,我是否可以对报告站点进行身份validation? 到目前为止,我所做的所有研究都让用户首先登录到父域,然后每个子域都可以访问身份validationcookie。