0

I am trying to set a cookie from withing a WebMethod like this

                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);

Now I want to redirect the user, after the user logged in, to a different page. I know I can't do this from the WebMethod. I return true to the jQuery Ajax call and then redirect the user using this

window.location.href = "/Pages/NonIssued";

But the redirection fails and takes keeps me in the login page, How can I Make the user logged in.

This is what I have in my 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>
Baso
  • 1,354
  • 4
  • 19
  • 41

0 Answers0