我计划用 HTML 和 SQL 构建一个站点。这是代码:Login.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Default2" %>
<!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>login</title>
<link href="main.css" rel="Stylesheet" type="text/css" />
</head>
<body dir="ltr">
<iframe src="menu.html" width="670px" height="170px" frameBorder="0" style="position:absolute;right:23em">
</iframe>
<img src="design\login2.jpg" height="300px" id="frc">
<form id="lgin" runat="server">
<table class="regtext">
<tr class="sec">
<td>username</td>
<td><input type="text" id="userName" name="userName" class="filld" </td>
</tr>
<tr>
<td>password</td>
<td><input type="password" id="pass" name="pass" class="filld" </td>
</tr>
<input type="submit" class="btn btn-large btn-warning" id="legbtn" value="login" />
</table>
<%=status %>
</form>
</body>
</html>
服务器端代码(C#):Login.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class login : System.Web.UI.Page
{
public string status = "";
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
string userName = Request.Form["userName"];
string password = Request.Form["pass"];
string sql = string.Format("SELECT * FROM Users WHERE userName='{0}' ", userName);
sql += string.Format("AND password='{0}'", password);
if (MyAdoHelper.IsExist("Database.mdf", sql))
{
Session["userName"] = userName;
sql = string.Format("SELECT * FROM Users WHERE userName='{0}' ", userName);
sql += string.Format("AND admin='{0}'", true);
if (MyAdoHelper.IsExist("Database.mdf", sql))
{
Session["admin"] = "admin";
Response.Redirect("Admin.aspx");
}
else
Response.Redirect("ForRegistered.aspx");
}
else
status = "error!";
}
}
}
错误是“当前上下文中不存在状态”。问题出在哪里?