您的位置:首页 > 其它

web.config配置的验证级别

2015-11-04 11:57 393 查看
应用情景---需要登录的网站,用户需登录之后才能到达其他的页面。

login界面中三个控件,用户名和密码输入框,提交按钮。

web.config中配置:

<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />

<authentication mode="Forms">
<forms name="myCookie" loginUrl="login.aspx">
</forms>
  </authentication>
<authorization>
<deny users="?"/>
</authorization>

</system.web>
</configuration>


在login.aspx.cs登录按钮事件中插入:

       if (Text1.Value == "mr" && Text2.Value == "mrsoft")
{
FormsAuthentication.SetAuthCookie(Text1.Value.Trim(), false);
Response.Write("<script>alert('登录成功!');location.href='Default.aspx';</script>");
}
else
{
Response.Write("<script>alert('登录失败!');</script>");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: