0

in my asp.net website i can only login in Firefox but not in chrome, internet explorer or safari.

here is my code :

    string userName = LoginUserName.Text;
    string password = LoginPassword.Text;

        if (Page.IsValid)
    {
        if (Membership.ValidateUser(userName, password))
        {
            if (RemeberMe.Checked == true)
            {
                Response.Redirect("~/Home.aspx");
            }
        }
    }

here is the login table :

        <table>
        <tr>
            <td>
                <asp:Label Text="Email:" AssociatedControlID="LoginUserName" runat="server" 
                    id="LoginUserNamelabel" CssClass="label"></asp:Label>
            </td>
        </tr>
        <tr>
            <td>
                <asp:TextBox ID="LoginUserName" runat="server" Width="250px" CssClass="textbox"/>
                <asp:RequiredFieldValidator id="LoginEmailRequired" runat="server" ControlToValidate="LoginUserName"
                    ErrorMessage="Email is required" ToolTip="Email is required"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td>
                <asp:Label Text="Password:" AssociatedControlID="LoginPassword" runat="server" 
                    ID="LoginPasswordlabel" CssClass="label"></asp:Label>
            </td>
        </tr>
        <tr>
            <td>
                <asp:TextBox ID="LoginPassword" runat="server" TextMode="Password" Width="250px" CssClass="textbox" />
                <asp:RequiredFieldValidator ID="PassRequired" runat="server" ControlToValidate="LoginPassword"
                    ErrorMessage="Password is Required" ToolTip="Password is Required"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td>
                <asp:CheckBox ID="RemeberMe" runat="server" Text="Remember me" CssClass="RemeberMe" />
            </td>
        </tr>
        <tr>
            <td><br />
                <asp:Button ID="LoginButton" runat="server" Text="Login" OnClick="autoLogin" CssClass="Button" />
            </td>
        </tr>
         <tr>
            <td><br />
                <asp:Label ID="FailureText" runat="server" EnableViewState="false" Visible="false" CssClass="Lfaluire">
                Wrong Email or Password</asp:Label>
            </td>
        </tr>
    </table>

using the AspNetSqlMembershipProvider.

i am using asp.net 4.0 , what is the problem thanks

Wahtever
  • 3,597
  • 10
  • 44
  • 79

3 Answers3

1

If you are hitting http://localhost then most of the browsers won't save the cookie that's being generated by your membership provider.

If this is the case, access it by a name that has a dot in it. See: Cookies on localhost with explicit domain

Community
  • 1
  • 1
NotMe
  • 87,343
  • 27
  • 171
  • 245
1

You always validate the username and password, but then only actually redirect if the user has checked the "Remember me" - This looks wrong. Could there be a co-incidence that you ticked the box in some test sessions but not others? ;)

Also you're not actually storing the fact that the user has logged in anywhere, so won't you have problems later with the User.Identity.IsAuthenticated still being false?

You should be using something like FormsAuthentication.RedirectFromLoginPage Method whether or not the checkbox is checked...

If you want to do the redirect yourself you should be using FormsAuthentication.SetAuthCookie and then doing the redirect.

EDIT: Something like this

string userName = LoginUserName.Text;
string password = LoginPassword.Text;

if (Page.IsValid)
{
    if (Membership.ValidateUser(userName, password))
    {
        if (RemeberMe.Checked)
        {
            // Set your own cookie here or something that you will later check for in Page_Load etc
        }

        // Need to tell ASP.NET authentication was successful
        System.Web.Security.FormsAuthentication.SetAuthCookie(userName, True)
        Response.Redirect("~/Home.aspx");
    }
}
bgs264
  • 4,572
  • 6
  • 38
  • 72
  • yes you are absolutely right i just noticed after posting the question the i wasn't actually logging the user in but more like validating his existence but Mozilla was using from the cache that's why i was able to login. and i use an else so if the check-box isn't checked it still continues. thanks – Wahtever Aug 03 '11 at 16:35
0

Are cookies enabled in all these browsers? The most common culprit to the out-of-the-box ASP.NET login stuff "not working" is because by default, they have no fallback for when cookies are disabled.

Rex M
  • 142,167
  • 33
  • 283
  • 313