为什么我的 asp.net 会员登录页面不能使用重定向?

Joh*_*ski 1 asp.net redirect asp.net-membership membership-provider returnurl

我使用 ASP.NET 会员资格提供程序在我的本地机器上设置了这个会员网站。当我去:

http://localhost/admin/

它把我重定向到

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

这很好。但是在我输入登录信息后,页面似乎刷新了。它实际上并没有让我登录,它看起来只是刷新了页面。如果我将 URL 更改为:

http://localhost/Login.aspx

它工作正常。它让我登录没问题,并将我重定向到我的默认页面。我还检查了实时站点,它也做同样的事情。有任何想法吗?提前致谢!

编辑:这是标记:

<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>
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

Meh*_*ari 5

你能告诉我们一些代码吗?如果你使用FormsAuthentication.RedirectFromLoginPage方法,你应该得到你想要的。你在用FormsAuthentication.SetAuthCookie吗?

更新

更改path="/Admin"web.configpath=/

它不起作用的原因是您的身份验证 cookie 仅在/Admin路径中设置,并且您的浏览器将 URL 视为区分大小写,因此它不会将身份验证 cookie 发送回/admin/Default.aspx页面(小写admin)。