标签:
应用情景---需要登录的网站,用户需登录之后才能到达其他的页面。
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>"); }
标签:
原文地址:http://www.cnblogs.com/lilixiang-go/p/4935533.html