登录并注销asp.net页面

时间:2014-05-30 11:24:16

标签: c# asp.net login formsauthentication

我需要在asp.net网站上创建一个登录页面。我在web.config文件中声明了这段代码:

    <location path="Login.aspx">
<system.web>
  <authorization>
    <allow users="*"/>
  </authorization>
</system.web>

    

<system.web><authentication mode="Forms">
  <forms name="MyAppCookie" loginUrl="Login.aspx" protection="All" timeout="30" defaultUrl="Managment.aspx" ></forms>

</authentication>

<authorization>
  <deny users="?"/>

</authorization><system.web>

我在Managment.aspx中有一个按钮退出运行此代码:

protected void Exit_Click(object sender, EventArgs e)
{
    FormsAuthentication.SignOut();
    FormsAuthentication.RedirectToLoginPage();
}

每件事都没问题,但是当我尝试使用退出按钮注销时,我给出了这个错误:

enter image description here  但我没有在地址栏中指定的帐户文件夹!我在网站root中只有一个Login.aspx文件。我希望通过单击此按钮将系统转换控制直接转换为Login.aspx页面。这样对吗?我该如何解决这个问题?

2 个答案:

答案 0 :(得分:2)

假设您的Login.aspx位于根文件夹中,请尝试使用

loginUrl="~/Login.aspx"

tilda表示法将使相对于网站根目录的路径不是当前页面。

答案 1 :(得分:1)

如果您的login.aspx保留在root中,请尝试

loginUrl =&#34; /Login.aspx"

相关问题