jetway_loves_programming之c#初学——登录界面程序
2011-04-15 21:11
465 查看
Login.aspx文件中,代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div style="height: 251px" id="Label1">
<asp:Label ID="Label7" runat="server" Font-Size="XX-Large" ForeColor="Maroon"
Height="35px" style="margin-left: 186px" Text="请登录" Width="103px"></asp:Label>
<br />
<br />
<asp:Label ID="Label2" runat="server" Font-Size="X-Large" ForeColor="#CC00CC"
Height="27px" style="margin-left: 90px" Text="用户:" Width="90px"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" Height="21px"></asp:TextBox>
<asp:RequiredFieldValidator ID = "RequiredFieldValidator1"
ControlToValidate = "TextBox1"
Display = "Dynamic"
ErrorMessage = "不能为空"
runat = "server" />
<br />
<br />
<asp:Label ID="Label3" runat="server" Font-Size="X-Large" ForeColor="#CC3399"
Height="27px" style="margin-left: 90px" Text="密码:" Width="87px"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" style="margin-left: 2px"></asp:TextBox>
<asp:RequiredFieldValidator ID = "RequiredFieldValidator2"
ControlToValidate = "TextBox2"
ErrorMessage = "密码不能为空"
runat = "server" />
<br />
<br />
<asp:CheckBox ID="Persist" runat="server" style="margin-left: 172px"
Text="记住密码" Width="120px" oncheckedchanged="Persist_CheckedChanged" />
<br />
<asp:Button ID="Submit1" OnClick="Login_Click" runat="server" Text="登陆"
Font-Names="黑体" Font-Size="X-Large" Height="42px" style="margin-left: 83px"
Width="76px" />
<asp:Label ID="Label4" runat="server" style="margin-left: 35px" Width="200px"></asp:Label>
</div>
</form>
</body>
</html>
Login.aspx.cs文件中,代码如下:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Login_Click(object sender, EventArgs e)
{
if ((TextBox1.Text == "sa") && (TextBox2.Text == "sa"))
{
FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, Persist.Checked);
}
else{
Label4.Text = "验证不成功,请再试一次";
}
}
}
代码参考如上,测试过应该没什么问题,当然了,之前还要在web.config中写入如下代码:
<authentication mode="Forms">
<forms loginUrl="Login.aspx" name=".aspsafetest">
</forms>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
然后把更改页面的form id,如上文中已经加上了[b]form id="form1"的字样,个人认为这表示的是程序执行时的登录顺序。
[/b]
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div style="height: 251px" id="Label1">
<asp:Label ID="Label7" runat="server" Font-Size="XX-Large" ForeColor="Maroon"
Height="35px" style="margin-left: 186px" Text="请登录" Width="103px"></asp:Label>
<br />
<br />
<asp:Label ID="Label2" runat="server" Font-Size="X-Large" ForeColor="#CC00CC"
Height="27px" style="margin-left: 90px" Text="用户:" Width="90px"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" Height="21px"></asp:TextBox>
<asp:RequiredFieldValidator ID = "RequiredFieldValidator1"
ControlToValidate = "TextBox1"
Display = "Dynamic"
ErrorMessage = "不能为空"
runat = "server" />
<br />
<br />
<asp:Label ID="Label3" runat="server" Font-Size="X-Large" ForeColor="#CC3399"
Height="27px" style="margin-left: 90px" Text="密码:" Width="87px"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" style="margin-left: 2px"></asp:TextBox>
<asp:RequiredFieldValidator ID = "RequiredFieldValidator2"
ControlToValidate = "TextBox2"
ErrorMessage = "密码不能为空"
runat = "server" />
<br />
<br />
<asp:CheckBox ID="Persist" runat="server" style="margin-left: 172px"
Text="记住密码" Width="120px" oncheckedchanged="Persist_CheckedChanged" />
<br />
<asp:Button ID="Submit1" OnClick="Login_Click" runat="server" Text="登陆"
Font-Names="黑体" Font-Size="X-Large" Height="42px" style="margin-left: 83px"
Width="76px" />
<asp:Label ID="Label4" runat="server" style="margin-left: 35px" Width="200px"></asp:Label>
</div>
</form>
</body>
</html>
Login.aspx.cs文件中,代码如下:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Login_Click(object sender, EventArgs e)
{
if ((TextBox1.Text == "sa") && (TextBox2.Text == "sa"))
{
FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, Persist.Checked);
}
else{
Label4.Text = "验证不成功,请再试一次";
}
}
}
代码参考如上,测试过应该没什么问题,当然了,之前还要在web.config中写入如下代码:
<authentication mode="Forms">
<forms loginUrl="Login.aspx" name=".aspsafetest">
</forms>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
然后把更改页面的form id,如上文中已经加上了[b]form id="form1"的字样,个人认为这表示的是程序执行时的登录顺序。
[/b]
相关文章推荐
- jetway_loves_programming之c#初学——如何利用asp.net生成word
- C#开发程序登录界面用户名和密码的验证
- C# 关于登录界面与主界面,关闭主界面程序不关闭的解决办法
- C#初学界面参考小程序
- C#写的简单的登录界面程序
- C#使用IrisSkin2.dll美化WinForm程序界面
- C#实现Discuz登录程序
- 设计用户登录界面的程序,逻辑问题
- C# 关闭登录窗体,进入主窗体后,主窗体关闭,程序进程仍在运行的问题
- Java小程序之GUI开发简单前台登录界面
- WINDOWS登录系统之前(欢迎界面)运行指定程序脚本服务
- C#中使用Windows API控制阿里旺旺自动登录 的程序源代码
- mstsc 远程序桌面登录的 c#开发
- 浅谈如何在C#Winform程序中正确使用登录窗体
- 初学JSP与Servlet之登录界面3.0版本
- C#程序登陆界面简单实现
- 一个简单的Android程序的登录界面
- C#使用IrisSkin2.dll美化WinForm程序界面
- 微信小程序实战(一)---实现登录界面
- unity 3D登录界面C#脚本