所以,我在 Controller 中有代码:
FormsAuthentication.SetAuthCookie("hello", true); throw new Exception("" + User.Identity.IsAuthenticated);
而且总是显示 false。可能是什么原因?
最佳答案
仅当用户开始发回 cookie 时,才会在下一个请求时对用户进行身份验证。表单例份验证仅在请求开始时发生。如果确实需要,您可以将 HttpContext.Current.User 更改为自定义的经过身份验证的身份,但您应该执行重定向。
关于c# - FormsAuthentication.SetAuthCookie 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20697766/