来自webmethod的表单身份验证

时间:2016-12-12 22:39:49

标签: asp.net webforms webmethod form-authentication

我正在尝试使用像这样的WebMethod来设置cookie

                FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, user.UserName,
                DateTime.Now, DateTime.Now.AddMinutes(60), user.RememberMe, user.Groups);

            //Encrypt the ticket.
            String encryptedTicket = FormsAuthentication.Encrypt(authTicket);

            //Create a cookie, and then add the encrypted ticket to the cookie as data.
            HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);

            if (true == user.RememberMe)
                authCookie.Expires = authTicket.Expiration;

            //Add the cookie to the outgoing cookies collection.
            HttpContext.Current.Response.Cookies.Add(authCookie);

现在,我希望在用户登录后将用户重定向到其他页面。我知道我无法通过WebMethod做到这一点。我返回jQuery Ajax调用,然后使用此

重定向用户
window.location.href = "/Pages/NonIssued";

但重定向失败并且让我保持在登录页面中,我该如何让用户登录。

这就是我在web.config中的内容

<authentication mode="Forms">
  <forms loginUrl="/Pages/LoginPage.aspx" name="adAuthCookie" timeout="30" slidingExpiration="true" defaultUrl="/Pages/NonIssued.aspx" path="/">
  </forms>
</authentication>
<authorization>
  <!--<allow roles="SDI\asfsadf aered 765" />
  <deny roles="SDI\SRD-Epac SQL Admins" />-->
  <deny users="?" />
  <allow users="*" />
</authorization>

0 个答案:

没有答案