Why is my asp.net login page not working with redirects?

I have this membership site setup on my local machine using an ASP.NET membership provider. When I go to:

http: // localhost / admin /

It redirects me to

http: //localhost/Login.aspx? ReturnUrl =% 2fadmin% 2fDefault.aspx

This is normal. But after I entered my registration information, the page seems to be refreshed. It is not actually logged in and it looks like it is refreshing the page. If I change the url to:

http: //localhost/Login.aspx

It works great. It logs me in with no problem and redirects me to my default page. I also checked the site and it does the same. Any ideas? Thanks in advance!

EDIT: here is the markup:

<asp:Login ID="Login1" runat="server" CssClass="LoginBox" TitleText="Please Log In">
    <LayoutTemplate>
        <h2>
            Please Log In:</h2>
        <p runat="server" id="FailureText" visible="false">
            Either your email address or password was incorrect. Please try again.</p>
        <strong>Email</strong><br />
        <asp:TextBox ID="UserName" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName"
            Text="*"></asp:RequiredFieldValidator>
        </p>
        <p>
            <strong>Password</strong><br />
            <asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>
            <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password"
                Text="*"></asp:RequiredFieldValidator>
        </p>
        <p>
            <asp:Button ID="Login" CommandName="Login" runat="server" Text="Log In" /></p>
        <p>
            Please <a runat="server" id="Link_ContactUs">contact </a>an administrator if you
            are having trouble logging in or have forgotten your password.</p>
    </LayoutTemplate>
</asp:Login>

      

Setting web.config:

<authentication mode="Forms">
  <forms loginUrl="/Login.aspx"
         protection="All"
         timeout="60"
         name="AppNameCookie"
         path="/Admin"
         requireSSL="false"
         slidingExpiration="true"
         defaultUrl="/Admin/Default.aspx"
         cookieless="UseCookies"
         enableCrossAppRedirects="false" />
</authentication>

      

+1


a source to share


1 answer


Can you show us some code? If you use the method FormsAuthentication.RedirectFromLoginPage

, you should get what you want. Are you using FormsAuthentication.SetAuthCookie

?

Update



Change path="/Admin"

in web.config

topath=/

The reason it doesn't work is because your authentication cookie is only set in the path /Admin

and your browser treats URLs as case sensitive, so it won't send the authentication cookie to the page /admin/Default.aspx

(lowercase admin

).

+4


a source







All Articles