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 valign="middle">
- <table valign="center" align="center" border="1" cellpadding="0" cellspacing="0" bordercolorlight="#003366" bordercolordark="#ffffff">
- <tr id="addData_TR" class="STYLE1" >
- <td colspan="2" align="center">
- 银行日记帐系统</td>
- </tr>
- <tr class="STYLE1">
- <td>用户名:</td>
- <td><input name="userName" type="text" id="Txt_LoginName" runat="server"/>
- <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="Txt_LoginName"
- ErrorMessage="请输入用户名!">*</asp:RequiredFieldValidator></td>
- </tr>
- <tr class="STYLE1">
- <td>
- 密 码:</td>
- <td><input name="psw" type="password" id="Txt_Password" runat="server" style=" 149px"/>
- <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="Txt_Password"
- ErrorMessage="请输入密码!">*</asp:RequiredFieldValidator></td>
- </tr>
- <tr>
- <td colspan="2" align="center" style="height: 26px">
- <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="登 录" />
- <input type="button" value="关 闭" onclick="window.opener=null;window.close();" />
- </td>
- </tr>
- </table>
- </div>
- </form>
- <script type="text/javascript">
- var oUserId = document.getElementById("Txt_LoginName");
- var oPwd = document.getElementById("Txt_Password");
- window.onload = function()
- {
- oUserId.focus();
- oUserId.onkeydown = function ()
- {
- if(event.keyCode == 13 ) oPwd.focus();
- }
- }
- </script>
- </body>
- </html>
------------------------------------------------------------------------------------
login.aspx.cs文件
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.Data.SqlClient;
- public partial class login : System.Web.UI.Page
- {
- protected SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["Conn"]);
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- string sql = "select * from person where name='" + this.Txt_LoginName.Value + "'";
- SqlDataAdapter cmd = new SqlDataAdapter(sql, conn);
- DataTable dt = new DataTable();
- cmd.Fill(dt);
- if (dt.Rows.Count == 1)
- {
- //Session["name"] = dt.Rows[0]["user_name"].ToString();
- Session["user_id"] = dt.Rows[0]["name"].ToString();
- Session["pwd"] = dt.Rows[0]["password"].ToString();
- //Session["flg"] = dt.Rows[0]["flg"].ToString();
- if (this.Txt_Password.Value == dt.Rows[0]["password"].ToString().Trim())
- {
- System.Web.Security.FormsAuthentication.RedirectFromLoginPage(this.Txt_LoginName.Value, false);
- this.Response.Redirect("index.aspx");
- }
- }
- if (dt.Rows.Count == 0)
- {
- this.RegisterStartupScript("T", "<script language=javascript>alert('没有这个账号,请检查输入是否正确!')</script>");
- }
- else if (dt.Rows.Count > 1)
- {
- this.RegisterStartupScript("T", "<script language=javascript>alert('账号有重复!')</script>");
- }
- }
- }
------------------------------------------------------------------------------------
index.aspx
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.aspx.cs" Inherits="index" %>
- <!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>
- 登陆成功!
- </div>
- </form>
- </body>
- </html>
---------------------------------------------------------------------------
index.aspx.cs
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- public partial class index : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- }
-----------------------------------------------------------------------------------
web.config文件
- <?xml version="1.0"?><!--
- 注意: 除了手动编辑此文件以外,您还可以使用
- Web 管理工具来配置应用程序的设置。可以使用 Visual Studio 中的
- “网站”->“Asp.Net 配置”选项。
- 设置和注释的完整列表在
- machine.config.comments 中,该文件通常位于
- WindowsMicrosoft.NetFrameworkv2.xConfig 中
- --><configuration>
- <appSettings>
- <add key="Conn" value="Data Source=localhost;Initial Catalog=dzjc_2005;User ID=sa;Password= " />
- <add key="DataBaseType" value="1" />
- <!--value为1表示连接的数据库是SQL,2表示oracle-->
- <add key="CrystalImageCleaner-AutoStart" value="true" />
- <add key="CrystalImageCleaner-Sleep" value="60000" />
- <add key="CrystalImageCleaner-Age" value="120000" />
- </appSettings>
- <system.web>
- <!--
- 设置 compilation debug="true" 将调试符号插入
- 已编译的页面中。但由于这会
- 影响性能,因此只在开发过程中将此值
- 设置为 true。
- -->
- <compilation debug="true">
- <assemblies>
- <add assembly="CrystalDecisions.Web, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
- <add assembly="CrystalDecisions.Shared, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
- <add assembly="CrystalDecisions.ReportSource, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
- <add assembly="CrystalDecisions.Enterprise.Framework, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
- <add assembly="CrystalDecisions.Enterprise.Desktop.Report, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
- <add assembly="CrystalDecisions.CrystalReports.Engine, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
- <add assembly="CrystalDecisions.Enterprise.InfoStore, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/><add assembly="CrystalDecisions.ReportAppServer.ClientDoc, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/></assemblies></compilation>
- <authorization>
- <deny users="?"/>
- </authorization>
- <authentication mode="Forms">
- <forms loginUrl="login.aspx" name=".App" timeout="7200"></forms>
- </authentication>
- <!--
- 通过 <authentication> 节可以配置 ASP.NET 使用的
- 安全身份验证模式,
- 以标识传入的用户。
- -->
- <!--<authentication mode="Windows"/>
- 如果在执行请求的过程中出现未处理的错误,
- 则通过 <customErrors> 节可以配置相应的处理步骤。具体说来,
- 开发人员通过该节可以配置
- 要显示的 html 错误页
- 以代替错误堆栈跟踪。
- <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
- <error statusCode="403" redirect="NoAccess.htm" />
- <error statusCode="404" redirect="FileNotFound.htm" />
- </customErrors>
- -->
- <httpHandlers><add verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/></httpHandlers></system.web>
- <location path="index">
- <system.web>
- <authorization>
- <allow users="*"/>
- </authorization>
- </system.web>
- </location>
- </configuration>