资源简介
次vs2008的网页设计是通过登陆页面,连接数据库,然后跳转到其他的页面的详细代码。
代码片段和文件信息
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;
using System.Data.SqlClient;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender EventArgs e)
{
if (IsPostBack == false)
if (Request.Cookies[“Users“] != null)
TextBoxUsers.Text = Request.Cookies[“Users“].Value;
}
protected void ButtonLogin_Click(object sender EventArgs e)
{
string Users = TextBoxUsers.Text.Trim();
string Pass = TextBoxPass.Text;
string role = RadioButtonListRole.SelectedValue;
bool result = false;
Response.Cookies[“Users“].Value = Users;
Response.Cookies[“Users“].Expires = DateTime.Now.AddDays(7);
try
{
string checkCode = TextBoxCheckCode.Text.Trim();
string correctCheckCode = Session[“CheckCode“].ToString();
if (checkCode != correctCheckCode)
{
LabelView.Text = “验证码错误“;
return;
}
}
catch (Exception)
{
LabelView.Text = “验证码工作异常“;
return;
}
try
{
SqlConnection con = new SqlConnection(“server=(local);database=login;uid=sa;pwd=123456;“);
con.Open();
string cmdStr =““;
if (role == “student“)
cmdStr = “SELECT COUNT(*) FROM [Students] WHERE [StId]=@Users AND [Pass]=@Pass“;
else if(role==“teacher“)
cmdStr = “SELECT COUNT(*) FROM [Teachers] WHERE [TeId]=@Users AND [Pass]=@Pass“;
else if (role == “admin“)
cmdStr = “SELECT COUNT(*) FROM [Admins] WHERE [AdId]=@Users AND [Pass]=@Pass“;
SqlCommand cmd = new SqlCommand(cmdStr con);
cmd.Parameters.AddWithValue(“@Users“ Users);
cmd.Parameters.AddWithValue(“@Pass“ Pass);
int cnt = Convert.ToInt32(cmd.ExecuteScalar());
con.Close();
if (cnt == 1)
result = true;
}
catch (SqlException ex)
{
LabelView.Text = “数据库连接失败“ + ex.Message;
}
if (result)
{
LabelView.Text = “登陆成功“;
Session[“Users“] = Users;
Session[“UserRole“] = role;
if(role==“student“)
Response.
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-04-06 17:37 WebApplication1\
目录 0 2018-04-15 14:06 WebApplication1\WebApplication1\
文件 935 2018-04-06 17:37 WebApplication1\WebApplication1.sln
文件 34816 2018-04-15 14:06 WebApplication1\WebApplication1.suo
目录 0 2018-04-15 11:46 WebApplication1\WebApplication1\Admin\
文件 536 2018-04-15 10:22 WebApplication1\WebApplication1\Admin\AdminDefault.aspx
文件 609 2018-04-15 10:22 WebApplication1\WebApplication1\Admin\AdminDefault.aspx.cs
文件 501 2018-04-15 10:16 WebApplication1\WebApplication1\Admin\AdminDefault.aspx.designer.cs
文件 535 2018-04-15 11:46 WebApplication1\WebApplication1\Admin\AdminSiteMap.sitemap
目录 0 2018-04-06 17:37 WebApplication1\WebApplication1\App_Data\
目录 0 2018-04-15 13:55 WebApplication1\WebApplication1\bin\
文件 10240 2018-04-15 14:01 WebApplication1\WebApplication1\bin\WebApplication1.dll
文件 32256 2018-04-15 14:01 WebApplication1\WebApplication1\bin\WebApplication1.pdb
文件 2570 2018-04-15 11:06 WebApplication1\WebApplication1\Default.aspx
文件 3453 2018-04-15 12:22 WebApplication1\WebApplication1\Default.aspx.cs
文件 3215 2018-04-15 10:54 WebApplication1\WebApplication1\Default.aspx.designer.cs
目录 0 2018-04-10 14:40 WebApplication1\WebApplication1\images\
文件 173271 2018-04-10 14:39 WebApplication1\WebApplication1\images\Logo.jpg
目录 0 2018-04-06 17:37 WebApplication1\WebApplication1\obj\
目录 0 2018-04-15 14:01 WebApplication1\WebApplication1\obj\Debug\
目录 0 2018-04-15 10:57 WebApplication1\WebApplication1\obj\Debug\Refactor\
目录 0 2018-04-06 17:37 WebApplication1\WebApplication1\obj\Debug\TempPE\
文件 409 2018-04-15 13:55 WebApplication1\WebApplication1\obj\Debug\WebApplication1.csproj.FileListAbsolute.txt
文件 10240 2018-04-15 14:01 WebApplication1\WebApplication1\obj\Debug\WebApplication1.dll
文件 32256 2018-04-15 14:01 WebApplication1\WebApplication1\obj\Debug\WebApplication1.pdb
目录 0 2018-04-06 17:37 WebApplication1\WebApplication1\Properties\
文件 1331 2018-04-06 17:37 WebApplication1\WebApplication1\Properties\AssemblyInfo.cs
文件 3126 2018-04-15 14:06 WebApplication1\WebApplication1\Site1.Master
文件 1437 2018-04-15 13:55 WebApplication1\WebApplication1\Site1.Master.cs
文件 2878 2018-04-15 14:01 WebApplication1\WebApplication1\Site1.Master.designer.cs
目录 0 2018-04-15 10:22 WebApplication1\WebApplication1\Students\
............此处省略19个文件信息
- 上一篇:自动售货机verilog代码
- 下一篇:跨站脚本攻击教程
评论
共有 条评论