登陆页面login.aspx出现错误
提示:这段代码错误{
log.AddLog(Session["user"] + "登陆系统", Session["user"].ToString()); }
Server.Transfer("Default.aspx");
那位兄弟能帮看看吗?
........................。。。。。。。。。。。。
全部代码如下:
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.Collections.Generic;
using BLL;
public partial class Login1 : System.Web.UI.Page
{
BLL.UserInfo user = new BLL.UserInfo();
SysLog log = new SysLog();
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
this.lblcheck.Text = CreateCode.CreateRandomCode(4);
Session["check"] = "";
}
}
protected void imgbLogin_Click(object sender, ImageClickEventArgs e)
{
string userName = this.txtUserName.Text;
string pwd = this.txtPwd.Text;
if (string.IsNullOrEmpty(this.txtUserName.Text) || string.IsNullOrEmpty(txtPwd.Text))
{
Page.ClientScript.RegisterClientScriptBlock(typeof(string), "script", "alert('用户名和密码不能为空!');", true);
}
else if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(pwd))
{
if(!string.IsNullOrEmpty(txtCheckCode.Text))
{
if (BLL.UserAdmin.UserBll.Login(txtUserName.Text, Comm.MD5(txtPwd.Text))==true)
{
if(txtCheckCode.Text.Trim().ToLower()==(this.lblcheck.Text.ToLower()))
{
Session["user"] =txtUserName.Text;
DataTable dt = BLL.UserAdmin.UserBll.GetUserByType(Session["user"].ToString());
if (dt.Rows[0]["UserType"].ToString() == "0" || dt.Rows[0]["UserType"].ToString() == "2")
{
log.AddLog(Session["user"] + "登陆系统", Session["user"].ToString());
}
Server.Transfer("Default.aspx");
}
else
{
Page.ClientScript.RegisterClientScriptBlock(typeof(string), "script", "alert('验证码错误!');", true);
this.lblcheck.Text = CreateCode.CreateRandomCode(4);
return;
}
}
else
{
Page.ClientScript.RegisterClientScriptBlock(typeof(string), "script", "alert('用户名和密码错误!');", true);
}
}
else
{
Page.ClientScript.RegisterClientScriptBlock(typeof(string), "script", "alert('请输入验证码!');", true);
}
}
else
{
Page.ClientScript.RegisterClientScriptBlock(typeof(string), "script", "alert('登录失败');", true);
}
}
}
--------------------编程问答-------------------- 报什么错?
. --------------------编程问答-------------------- 贴出错误信息 --------------------编程问答-------------------- 是不是Session["user"]为NULL,从而导致Session["user"].ToString()无法执行,所以就报错喽。你加点判断试试,或者断点调试下 --------------------编程问答-------------------- --------------------编程问答--------------------
log.AddLog(Session["user"] + "登陆系统", Session["user"].ToString());
这句话中session 是不能与字符串直接相加的,需要.ToString();
如果是提示“未将引用添加到实例”的话就是session["user"]没有设置就进行了访问。
加:
if(session["user"]!=null)
{
log.AddLog(Session["user"] + "登陆系统", Session["user"].ToString());
} --------------------编程问答-------------------- Session["user"]==null?"":Session["user"].ToString() --------------------编程问答-------------------- log.AddLog(Session["user"].ToString() + "登陆系统", Session["user"].ToString()); --------------------编程问答-------------------- 感谢楼上各位的指教,试过后,没有解决问题,现贴出错误提示信息:
用户 'sa' 登录失败。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.SqlClient.SqlException: 用户 'sa' 登录失败。
源错误:
行 48: if (dt.Rows[0]["UserType"].ToString() == "0" || dt.Rows[0]["UserType"].ToString() == "2")
行 49: {
行 50: log.AddLog(Session["user"] + "登陆系统", Session["user"].ToString());
行 51: }
行 52: Server.Transfer("Default.aspx");
源文件: d:\big-wuye\UI\Login.aspx.cs 行: 50
堆栈跟踪:
[SqlException (0x80131904): 用户 'sa' 登录失败。]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4846887
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2392
System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +35
System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +144
System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +342
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +221
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +189
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +185
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +31
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +433
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +499
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +65
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117
System.Data.SqlClient.SqlConnection.Open() +122
DAL.AdminManage.AdminTableAdapters.SysLogTableAdapter.AddLog(String Event, String Handler) in G:\45修改前\XiangyueManage\DAL\AdminManage\Admin.Designer.cs:6674
BLL.SysLog.AddLog(String even, String handler) in G:\45修改前\XiangyueManage\BLL\SysLog.cs:45
Login1.imgbLogin_Click(Object sender, ImageClickEventArgs e) in d:\big-wuye\UI\Login.aspx.cs:50
System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +108
System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +118
System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
--------------------编程问答-------------------- 配置“连接数据库”出错了。。。。
--------------------编程问答-------------------- 数据库登录错误···· 用户密码是否正确,是否对该数据库有访问权限? --------------------编程问答-------------------- 数据库连接错误 检查数据库连接字符串 --------------------编程问答-------------------- 先用windows sqlserver混合验证 登陆
在这个你登陆的服务器---》右键-------------》属性---------》
安全性----------》windows 和sql server 身份验证模式----------》确定
找一个 安全性 里的----》登录名----》 有个sa用户
选择sa 右键属性。
然后有个状态,把禁用设置为启用。
还需要修改密码。如:sa
把强制实施密码策略的勾选去掉!
操作完后,需要停止sql server服务,再重新打开,一般就行了!!!
--------------------编程问答--------------------
连接字符串有问题,你可以sqldatasource,连接成功以后用它生成的连接字符串就可以了。
补充:.NET技术 , ASP.NET