public partial class SampleUser
{
string username;
public string UserName
{
get { return username; }
set { username = value; }
}
string userpwd;
public string UserPWD
{
get { return userpwd; }
set { userpwd = value; }
}
public override bool Equals(object obj)
{
SampleUser other = obj as SampleUser;
if (other == null || other.UserName != this.UserName)
return false;
return true;
}
}
public partial class SampleUser
{
public static List<SampleUser> userList = new List<SampleUser> {
new SampleUser() { UserName = "01", UserPWD = "123"},
new SampleUser() { UserName = "02", UserPWD = "123" },
new SampleUser() { UserName = "03", UserPWD = "123" },
new SampleUser() { UserName = "04", UserPWD = "123" },
};
public static SampleUser GetUser(string userName)
{
return userList.Find(u=>u.UserName == userName);
}
}
<authentication mode="Forms"> <forms loginUrl="~/Login.aspx" defaultUrl="~/Default.aspx" /> </authentication> <authorization> <deny users="?"/> </authorization>
<fieldset>
<legend>用户登陆</legend>
<div>
用户名:<asp:TextBox ID="txtUserID" runat="server" Width="150" /><br /><br />
密 码:<asp:TextBox ID="txtUserPWD" runat="server" TextMode="Password" Width="150" /><br /><br />
<asp:CheckBox ID="cbSaveUserName" runat="server" Checked="true" Text="保持登录状态" />
</div><br />
<asp:Literal ID="ltMessage" Text="" runat="server" Visible="false" />
<br />
<p>
<asp:Button ID="btnLogin" Text="登陆" runat="server" OnClick="btnLogin_Click" />
</p>
</fieldset>
protected void btnLogin_Click(object sender, EventArgs e)
{
string userID = this.txtUserID.Text.Trim();
string userPWD = this.txtUserPWD.Text.Trim();
SampleUser userEx = SampleUser.GetUser(userID);
if (userEx == null)
{
ltMessage.Text = "用户不存在!";
ltMessage.Visible = true;
return;
}
if (userEx.UserPWD != userPWD)
{
ltMessage.Text = "用户名或密码错误,请重新输入!";
ltMessage.Visible = true;
return;
}
//添加票据,并将用户导航到默认页面
FormsAuthentication.RedirectFromLoginPage(userEx.UserName, this.cbSaveUserName.Checked);
}
<authorization> <allow users="?"/> </authorization>
<authorization>
<deny users="?"/>
</authorization>
<h2> <p>用户名:<asp:Label ID="lblUserName" Text="" runat="server" /></p> <p>密 码:<asp:Label ID="lblUserPWD" Text="" runat="server" /></p> </h2>
if (this.Context.User != null && this.Context.User.Identity != null && this.Context.User.Identity.IsAuthenticated)
{
SampleUser user = SampleUser.GetUser(this.Context.User.Identity.Name);
if (user != null)
{
this.lblUserName.Text = user.UserName;
this.lblUserPWD.Text = user.UserPWD;
}
}
FormsAuthentication.SignOut(); //退出登陆
<forms name="name" loginUrl="URL" defaultUrl="URL" protection="[All|None|Encryption|Validation]" timeout="[MM]" path="path" requireSSL="[true|false]" slidingExpiration="[true|false]"> enableCrossAppRedirects="[true|false]" cookieless="[UseUri|UseCookie|AutoDetect|UseDeviceProfile]" domain="domain name" ticketCompatibilityMode="[Framework20|Framework40]"> <credentials>...</credentials> </forms>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有