我做好一个登录页面后进行调试没问题,代码也没有错的地方,但是点击注册按钮时没有转到响应的页面,哪个高手帮我看一下是哪里出了问题,非常感谢!!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 style="text-align:center;">
<form id="form1" runat="server">
<table style="width:980;" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td style="width:980px; " align="center" >
<table id="header" width="100%" border="0" style="background-color:Green;">
<tr>
<td style="height:150px;"></td>
</tr>
</table>
<table id="main" width="100%" style="height:300px; border-color:Red;" border="1" >
<tr id="1" style="height:60px;">
<td rowspan="3" style="width:200px; height:60px; background-color:Red;">
</td>
<td style="width:580px; height:60px;" align="center">
<asp:Label ID="Label1" runat="server" Text="用户名:"></asp:Label>
<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1" ControlToValidate="txtUserName" runat="server" ErrorMessage="用户名不能为空"></asp:RequiredFieldValidator>
</td>
<td style="width:200px; height:60px;" align="left"></td>
</tr>
<tr id="2">
<td style="width:580px; height:60px;" align="center">
<asp:Label ID="Label2" runat="server" Text="密 码:"></asp:Label>
<asp:TextBox ID="txtPw" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator2" ControlToValidate="txtPw" runat="server" ErrorMessage="密码不能为空"></asp:RequiredFieldValidator>
</td>
<td style="width:200px; height:60px;" align="left"></td>
</tr>
<tr id="3">
<td style="width:580px; height:60px;" align="center">
<asp:Button ID="btnOK" runat="server" Text="登录" OnClick="btnOK_Click" />
<asp:Button ID="btnAdd" runat="server" Text="考生注册" OnClick="btnAdd_Click" />
</td>
<td style="width:200px; height:60px;" align="left"></td>
</tr>
</table>
</td>
</tr>
</table>
<div>
</div>
</form>
</body>
</html>Login.aspx.csusing 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 Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnOK_Click(object sender, EventArgs e)
{
Auth auth = new Auth();
int userid = 0;
if (auth.Login(txtUserName.Text, txtPw.Text, out userid))
{
string[] role = auth.LoginType(txtUserName.Text);
Identity identity = new Identity(txtUserName.Text.Trim(), userid);
Context.User = new Principal(identity, role);
//获取用户名
identity.Name = txtUserName.Text;
identity.Roles = role[0];
identity.Save();
FormsAuthentication.SetAuthCookie(txtUserName.Text, false);
//根据不同的身份进入不同的页面
string type = ((Principal)HttpContext.Current.User).Roles[0]; if (type == "Admin")
{
Response.Redirect("Admin/Admin.aspx");
}
else
{
Response.Redirect("Student/Student.aspx");
}
}
else
{
Response.Write(" '登录失败!");
}
}
protected void btnAdd_Click(object sender, EventArgs e)
{
Response.Redirect("AddUser.aspx?Action=add");
}
}
<%@ 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 style="text-align:center;">
<form id="form1" runat="server">
<table style="width:980;" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td style="width:980px; " align="center" >
<table id="header" width="100%" border="0" style="background-color:Green;">
<tr>
<td style="height:150px;"></td>
</tr>
</table>
<table id="main" width="100%" style="height:300px; border-color:Red;" border="1" >
<tr id="1" style="height:60px;">
<td rowspan="3" style="width:200px; height:60px; background-color:Red;">
</td>
<td style="width:580px; height:60px;" align="center">
<asp:Label ID="Label1" runat="server" Text="用户名:"></asp:Label>
<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1" ControlToValidate="txtUserName" runat="server" ErrorMessage="用户名不能为空"></asp:RequiredFieldValidator>
</td>
<td style="width:200px; height:60px;" align="left"></td>
</tr>
<tr id="2">
<td style="width:580px; height:60px;" align="center">
<asp:Label ID="Label2" runat="server" Text="密 码:"></asp:Label>
<asp:TextBox ID="txtPw" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator2" ControlToValidate="txtPw" runat="server" ErrorMessage="密码不能为空"></asp:RequiredFieldValidator>
</td>
<td style="width:200px; height:60px;" align="left"></td>
</tr>
<tr id="3">
<td style="width:580px; height:60px;" align="center">
<asp:Button ID="btnOK" runat="server" Text="登录" OnClick="btnOK_Click" />
<asp:Button ID="btnAdd" runat="server" Text="考生注册" OnClick="btnAdd_Click" />
</td>
<td style="width:200px; height:60px;" align="left"></td>
</tr>
</table>
</td>
</tr>
</table>
<div>
</div>
</form>
</body>
</html>Login.aspx.csusing 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 Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnOK_Click(object sender, EventArgs e)
{
Auth auth = new Auth();
int userid = 0;
if (auth.Login(txtUserName.Text, txtPw.Text, out userid))
{
string[] role = auth.LoginType(txtUserName.Text);
Identity identity = new Identity(txtUserName.Text.Trim(), userid);
Context.User = new Principal(identity, role);
//获取用户名
identity.Name = txtUserName.Text;
identity.Roles = role[0];
identity.Save();
FormsAuthentication.SetAuthCookie(txtUserName.Text, false);
//根据不同的身份进入不同的页面
string type = ((Principal)HttpContext.Current.User).Roles[0]; if (type == "Admin")
{
Response.Redirect("Admin/Admin.aspx");
}
else
{
Response.Redirect("Student/Student.aspx");
}
}
else
{
Response.Write(" '登录失败!");
}
}
protected void btnAdd_Click(object sender, EventArgs e)
{
Response.Redirect("AddUser.aspx?Action=add");
}
}
Response.Redirect("AddUser.aspx?Action=add");上面这句你用Server.transfer("URL")替换一下。--------------
其实你的btnAdd按钮,没有别的作用,只为了跳转一下添加用户注册页面,完全没必要用服务器控件Buuton,你这个用<a href='AddUser.aspx?Action=add'>考生注册</a>,就完全可以了。