我已在web.config里配置了 <authentication mode="Forms">
<forms name="webs" loginUrl="Login.aspx">
</forms>
</authentication>我在用户名和密码框都输入值后,点登录按钮后很快就又回到了这个登录页面,什么都不提示,登录验证我是写在login.asp.cs里的,请问这是怎么回事
<%@ Page language="c#" Codebehind="login.aspx.cs" AutoEventWireup="false" Inherits="Webs.login" %>
<HTML>
<HEAD>
<title>login</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
BODY { BACKGROUND-COLOR: #619bd8 }
</style>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="login" method="post" runat="server" >
<FONT face="宋体"></FONT><FONT face="宋体"></FONT>
<br>
<br>
<br>
<table width="360" height="55" border="0" align="center" cellpadding="0" cellspacing="0"
bgcolor="#cccccc">
<tr>
<td colspan="2" align="center"><img src="images/login_win.gif" width="360" height="170"></td>
</tr>
<tr>
<td width="130" height="41" align="right" style="WIDTH: 130px; HEIGHT: 41px">用户名:</td>
<td width="319" height="41" style="HEIGHT: 41px">
<asp:TextBox ID="username" runat="server" />
<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ErrorMessage="用户名" Width="9px" ControlToValidate="username">*</asp:RequiredFieldValidator></td>
</tr>
<tr>
<td height="30" align="right" style="WIDTH: 130px">密 码:</td>
<td height="30">
<asp:TextBox ID="password" runat="server" TextMode="Password" />
<asp:RequiredFieldValidator id="RequiredFieldValidator2" runat="server" ErrorMessage="密码" Width="9px" ControlToValidate="password">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td height="15" colspan="2">
<asp:ValidationSummary id="ValidationSummary1" runat="server" HeaderText="请正确填入以下的内容:"></asp:ValidationSummary></td>
</tr>
<tr align="center">
<td height="15" colspan="2"><asp:button id="btnlogin" runat="server" Width="66px" Text="登录" Height="29px"></asp:button></td>
</tr>
</table>
</form>
</body>
</HTML>
<forms name="webs" loginUrl="Login.aspx">
</forms>
</authentication>我在用户名和密码框都输入值后,点登录按钮后很快就又回到了这个登录页面,什么都不提示,登录验证我是写在login.asp.cs里的,请问这是怎么回事
<%@ Page language="c#" Codebehind="login.aspx.cs" AutoEventWireup="false" Inherits="Webs.login" %>
<HTML>
<HEAD>
<title>login</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
BODY { BACKGROUND-COLOR: #619bd8 }
</style>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="login" method="post" runat="server" >
<FONT face="宋体"></FONT><FONT face="宋体"></FONT>
<br>
<br>
<br>
<table width="360" height="55" border="0" align="center" cellpadding="0" cellspacing="0"
bgcolor="#cccccc">
<tr>
<td colspan="2" align="center"><img src="images/login_win.gif" width="360" height="170"></td>
</tr>
<tr>
<td width="130" height="41" align="right" style="WIDTH: 130px; HEIGHT: 41px">用户名:</td>
<td width="319" height="41" style="HEIGHT: 41px">
<asp:TextBox ID="username" runat="server" />
<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ErrorMessage="用户名" Width="9px" ControlToValidate="username">*</asp:RequiredFieldValidator></td>
</tr>
<tr>
<td height="30" align="right" style="WIDTH: 130px">密 码:</td>
<td height="30">
<asp:TextBox ID="password" runat="server" TextMode="Password" />
<asp:RequiredFieldValidator id="RequiredFieldValidator2" runat="server" ErrorMessage="密码" Width="9px" ControlToValidate="password">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td height="15" colspan="2">
<asp:ValidationSummary id="ValidationSummary1" runat="server" HeaderText="请正确填入以下的内容:"></asp:ValidationSummary></td>
</tr>
<tr align="center">
<td height="15" colspan="2"><asp:button id="btnlogin" runat="server" Width="66px" Text="登录" Height="29px"></asp:button></td>
</tr>
</table>
</form>
</body>
</HTML>
<forms name="webs" loginUrl="Login.aspx">
</forms>
</authentication>
改为:
<authentication mode="Forms">
<forms name=".ASPXUSERDEMO" loginUrl="Login.aspx" protection="All" timeout="30"/>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
我是直接与sql库对比.
是调用了下面的方法?
FormsAuthentication.SetAuthCookie:
Creates an authentication ticket and attaches it to the cookie's collection of the outgoing response. It does not perform a redirect.
否则Request.IsAuthenticated就是false,当前的请求将不会被认证。name="webs"这个不用改,这是客户端cookie的名字。
FormsAuthentication.SetAuthCookie
<authentication mode="Forms">
<forms name=".ASPXUSERDEMO" loginUrl="Login.aspx" protection="All" timeout="30"/>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
我已经改为了这个,还是没反应请问一下Request.IsAuthenticated 和Request.IsAuthenticated哪里设置
.cs文件
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace Webs
{
/// <summary>
/// login 的摘要说明。
/// </summary>
public class login : System.Web.UI.Page
{
private string invalidLogin = string.Empty;
protected System.Web.UI.WebControls.TextBox username;
protected System.Web.UI.WebControls.TextBox password;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
protected System.Web.UI.WebControls.ValidationSummary ValidationSummary1;
protected System.Web.UI.WebControls.Button btnlogin;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
private void btnlogin_click(object sender,System.EventArgs e)
{
EmpDB AloginUsr=new EmpDB();
String strLoginID=username.Text.Trim();
String strPassword=password.Text.Trim();
string strReaseon;
string strUserID;
string strValid;
string[] NewLogin; //调用数据层验证服务,得到验证结果
String[] strLoginflag=AloginUsr.Login(strLoginID,strPassword); //判断验证结果
if(strLoginflag[0]=="usererror"||strLoginflag[0]=="pwderror"||strLoginflag[0]=="noacount")
{
//写入登录日志
strUserID = username.Text .Trim ();
strValid= "否";
strReason=strLoginflag[1]; //这里有数组记录登录信息
NewLogin=new string []
{
strUserID,
DateTime.Now .ToString (),
strValid,
"",
Request.UserHostAddress .ToString (),
strReason
};
//调用数据访问层的日志记录服务,记录登录信息
DbManagerLogininfo myclassfologin=new DbManagerLogininfo ();
myclassfologin.insertLoginUser (NewLogin);
//向页面输出错误提示信息
Response.Write("<script language=javascript>");
Response.Write("window.alert('");
Response.Write(strReason);
Response.Write("');");
Response.Write("</script>");
}
//否则登录成功
else
{
//记录cookie,设置10天过期
Response.Cookies["empint"].Value=username.Text;
Response.Cookies["empint"].Expires=DateTime.Now.AddDays(1);
//写入登录日志
strUserID=username.Text .Trim ();
strValid="是";
strReason="";
strReason=strLoginflag[1];
NewLogin=new string []
{
strUserID,
DateTime.Now .ToString (),
strValid,
"",
Request.UserHostAddress .ToString (),
strReason
}; //调用数据访问层的日志记录服务,记录登录成功信息
DbManagerLogininfo myclassfologin=new DbManagerLogininfo ();
myclassfologin.insertLoginUser (NewLogin);
Session["EmpID"]=Int32.Parse(strLoginflag[0]);
Session["username"]=username.Text; //引导用户进入系统主页面,定制主页面
string tt="qminoa = window.open('"+Request.ApplicationPath+"/index.aspx"+"'"
+",'','toolbar=no,menubar=no,titlebar=yes,directories=no,resizable=yes,status=yes,fullscreen=no,top=0;left=0,width=900,height=700');";
Response.Write("<script language=javascript>");
Response.Write(tt);
//设置系统主页面全屏
Response.Write("qminoa.moveTo(0,0);");
Response.Write("qminoa.resizeTo(screen.availWidth,screen.availHeight);");
//记录登录窗口
Response.Write("window.opener=null;");
Response.Write("window.close();");
Response.Write("</script>");
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
}
}