Tag: formsauthentication

使用formsauthentication进行登录并使用HttpContext.Current.User.Identity

我创建了一个包含剃刀forms页面的网站。 用户可以登录此表单,然后重定向到其他页面。 登录(和注销)成功地与formsauthentication一起使用。 但是,我似乎无法使用HttpContext.Current.User.Identity.Name来检索存储的用户名(在formsauthentication cookie中)。 它返回一个空字符串“”。 我使用的是MVC 5和ASP 4.5,没有标准的成员资格或角色提供者。 登录: [HttpPost] public ActionResult Login(User user) { if (ModelState.IsValid) { bool authenticated = userscontroller.isAuthorized(user.Email, user.Password); if (authenticated) { if (userscontroller.isAuthenticated()) { userscontroller.deAuthenticateUser(); } userscontroller.authenticateUser(user); return Redirect(Url.Action(“Index”, “Home”)); } } } validation用户: public void authenticateUser(User user) { FormsAuthentication.SetAuthCookie(user.Username, false); } 然后获取用户的名称: public User userFromCookie() { if (isAuthenticated()) […]

System.Web可以与带有完整框架的ASP.Net Core一起使用

我们基于不同的.Net版本运行多个站点。 其中一个站点运行.Net 4.6和ASP.Net MVC 5.xx 要使用Razor的新语法,我们希望将此站点升级为使用.Net 4.6和ASP.Net Core 我们在我们的网站上使用FormsAuthentication,我们将继续使用它,以便用户可以在网站之间移动。 (其中一个站点是运行FormsAuthentication的SharePoint站点) 我们知道ASP.Net Core没有使用System.Web中的任何内容,但我们需要使用来自控制器(在登录时创建FormsAuthentication cookie)和HttpModule来validationcookie。 我无法找到如何使用完整框架运行ASP.Net Core的站点中的system.web的任何示例。 我无法在project.json中添加system.web的依赖项。 问题。 是否可以从这样的设置中使用system.web? 我们如何向system.web添加依赖性,以便ASP.NET MVC 6中提供System.Web.FormsAuthentication。(Controllers / http模块)