1
请注意这里的母版页编号网络使用登录控制和LoginView成功登录后,页面重定向
<asp:LoginView ID="LoginView1" runat="server" ViewStateMode="Disabled">
<AnonymousTemplate>
<ul>
<li><a id="registerLink" runat="server" href="~/LogReg.aspx">Register</a></li>
<li><a id="loginLink" runat="server" href="~/LogReg.aspx">Log in</a></li>
</ul>
</AnonymousTemplate>
<LoggedInTemplate>
<ul>
<li><a id="manage" runat="server" class="username" href="~/Account/Manage.aspx" title="Manage your account">
<asp:LoginName ID="LoginName2" runat="server" CssClass="username" />
</a>
</li>
<li><a id="A2" runat="server" href="~/Logout.aspx">Log Out</a></li>
</ul>
</LoggedInTemplate>
</asp:LoginView>
这是登录页面代码
<asp:Login ID="Login1" runat="server" Height="198px" Width="297px" DisplayRememberMe="False" OnAuthenticate="Login1_Authenticate" UserNameLabelText="Email:">
<InstructionTextStyle Font-Italic="True" ForeColor="Black" />
<LoginButtonStyle Font-Size="Small" />
<TextBoxStyle Font-Size="0.8em" CssClass="float-right" Width="180px" Height="12px" />
<LabelStyle CssClass="float-left" />
<TitleTextStyle CssClass="task-title" />
</asp:Login>
登录控制的认证事件看起来像:
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
string un = Login1.UserName;
string pw = Login1.Password;
var c = db.customers.Where(s => s.customer_email == un && s.customer_password == pw && s.customer_deleted != true);
if (c.Count() == 1)
{
e.Authenticated = true;
//Something to redirect //Response.Redirect(Page.PreviousPage.ToString());
}
else
e.Authenticated = false;
}
问题是,当我在这里使用Response.Redirect函数时,它成功重定向,但loginView模板返回到anonymousTemplate。如果我不使用重定向,模板将更改为LoggedInTemplate,但我想将其重定向到上一页。我使用了destinationPageUrl属性,但它的行为是一样的。感谢您的帮助:)
太棒了!谢谢:) – 2014-09-13 15:46:19
Page.PreviousPage在这个事件中显示为null,你能不能请告诉我应该采取什么措施重定向到上一页,而不是使用会话? 谢谢,现在明白了。 – 2014-09-13 15:56:15
您可以尝试** Request.UrlReferrer **。但是,我不推荐任何一个,因为它们不可靠。相反,我们通常在QueryString **中使用** ReturnUrl。 – Win 2014-09-13 16:01:07