3
Reply

Login page works fine on localhost but does not on server?

Anh Duc Thai

Anh Duc Thai

Jan 13 2008 3:56 AM
3.6k
I made a custom login page for my website. The login feature worked fine when i ran it on localhost. But had problem when it was uploaded to the server.
After the user entered his valid cridential, and the Identity.IsAuthenticated was true as well as Identiy.Name was not null. But still cannot direct to the protected page. The login page just kept the same.
Here are some code:
Web config:
 <sessionState mode="InProc"></sessionState>
         <authentication mode="Forms">
             <forms loginUrl="Login.aspx" path="/"
              defaultUrl="Default.aspx"
              protection="All"
              timeout="60"
              name=".OnlineShop"
               slidingExpiration="true" requireSSL="false">
             </forms>
         </authentication>
        <authorization>
        <deny users="?"/>
      </authorization>

Code from login page:
 string username = this.txtUserName.Text.Trim();
               bool persistent = this.chkPersistent.Checked;
               FormsAuthentication.Initialize();
               FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
                  username,
                  DateTime.Now,
                  DateTime.Now.AddMinutes(30),
                  persistent,
                  "User",
                  FormsAuthentication.FormsCookiePath);

               // Encrypt the ticket.
               string encTicket = FormsAuthentication.Encrypt(ticket);

               // Create the cookie.
               Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));
               string returnUrl = Request["ReturnUrl"];
               if (string.IsNullOrEmpty(returnUrl))
                  returnUrl = GetVirtualPath() + "Default.aspx";
               // Redirect back to original URL.
               Response.Redirect(returnUrl);


Does anyone have some clues about my problem? It made me crazy for days.
Note: It works fine when running locally.

Answers (3)