我是一个ASP.Net 3.5(C#)Web应用程序,它使用Sql Server 2008作为其数据库。在该db中是一个标准用户表,其中包含用户名/密码列,我有一个简单的登录表单来验证用户。登录页面简单查询表格,以查找输入值的用户名/密码组合。如果用户输入有效的用户名/密码,它可以正常工作并继续,但是如果由于某种原因无效组合它会抛出错误而不是简单地找不到匹配。错误是:
System.Web消息:类型异常 ' System.Web.HttpUnhandledException'被扔了。堆栈跟踪:at System.Web.UI.Page.HandleError(Exception e)at System.Web.UI.Page.ProcessRequestMain(布尔 includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint) 在System.Web.UI.Page.ProcessRequest(布尔值 includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint) 在System.Web.UI.Page.ProcessRequest()处 System.Web.UI.Page.ProcessRequest(HttpContext context)at ASP.login_aspx.ProcessRequest(HttpContext context)中 c:\ Windows \ Microsoft.NET \ Framework64 \ v2.0.50727 \ Temporary ASP.NET Files \ root \ 55c40ade \ 918a8ce7 \ App_Web_xyhtxem7.17.cs:第0行at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 在System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤, 布尔和放大器; completedSynchronously)完成错误文本: System.Web.HttpUnhandledException:类型的异常 ' System.Web.HttpUnhandledException'被扔了。 ---> System.Data.SqlClient.SqlException:无法生成用户实例 SQL Server由于启动用户进程失败而导致的 实例。连接将被关闭。在 System.Data.SqlClient.SqlInternalConnection.OnError(SQLEXCEPTION exception,Boolean breakConnection)at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)在System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj)at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(布尔 enlistOK)at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo,String newPassword,Boolean ignoreSniOpenTimeout,Int64 timerExpire,SqlConnection owningObject)at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(字符串 host,String newPassword,Boolean redirectedUserInstance, SqlConnection owningObject,SqlConnectionString connectionOptions, Int64 timerStart)at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(的SqlConnection owningObject,SqlConnectionString connectionOptions,String newPassword,Boolean redirectedUserInstance)at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity,SqlConnectionString connectionOptions,Object providerInfo, String newPassword,SqlConnection owningObject,Boolean redirectedUserInstance)at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options,Object poolGroupProviderInfo,DbConnectionPool池, DbConnection owningConnection)at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(的DbConnection owningConnection,DbConnectionPool池,DbConnectionOptions选项) 在System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection 拥有对象) System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(的DbConnection 拥有对象) System.Data.ProviderBase.DbConnectionPool.GetConnection(的DbConnection 拥有对象) System.Data.ProviderBase.DbConnectionFactory.GetConnection(的DbConnection 拥有连接) System.Data.ProviderBase.DbConnectionClosed.OpenConnection(的DbConnection outerConnection,DbConnectionFactory connectionFactory)at System.Data.SqlClient.SqlConnection.Open()at System.Web.DataAccess.SqlConnectionHolder.Open(HttpContext context, 布尔值revertImpersonate)at System.Web.DataAccess.SqlConnectionHelper.GetConnection(字符串 connectionString,Boolean revertImpersonation)at System.Web.Security.SqlMembershipProvider.GetPasswordWithFormat(字符串 username,Boolean updateLastLoginActivityDate,Int32& status,String& 密码,Int32& passwordFormat,String& passwordSalt,Int32& failedPasswordAttemptCount,Int32& failedPasswordAnswerAttemptCount, 布尔和放大器; isApproved,DateTime& lastLoginDate,DateTime& lastActivityDate)at System.Web.Security.SqlMembershipProvider.CheckPassword(字符串 username,String password,Boolean updateLastLoginActivityDate, Boolean failIfNotApproved,String&盐,Int32& passwordFormat)at System.Web.Security.SqlMembershipProvider.ValidateUser(字符串 用户名,字符串密码)at System.Web.UI.WebControls.Login.AuthenticateUsingMembershipProvider(AuthenticateEventArgs e)在System.Web.UI.WebControls.Login.AttemptLogin()at System.Web.UI.WebControls.Login.OnBubbleEvent(Object source,EventArgs e)在System.Web.UI.Control.RaiseBubbleEvent(Object source,EventArgs args)在System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler) sourceControl,String eventArgument)at System.Web.UI.Page.ProcessRequestMain(布尔 includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint) ---内部异常堆栈跟踪的结束---在System.Web.UI.Page.HandleError(Exception e)处 System.Web.UI.Page.ProcessRequestMain(布尔 includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint) 在System.Web.UI.Page.ProcessRequest(布尔值 includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint) 在System.Web.UI.Page.ProcessRequest()处 System.Web.UI.Page.ProcessRequest(HttpContext context)at ASP.login_aspx.ProcessRequest(HttpContext context)中 c:\ Windows \ Microsoft.NET \ Framework64 \ v2.0.50727 \ Temporary ASP.NET Files \ root \ 55c40ade \ 918a8ce7 \ App_Web_xyhtxem7.17.cs:第0行at System.Web.HttpApplication
任何想法发生了什么?
答案 0 :(得分:0)
如果你不匹配sql结果可能是NULL。因此,您无法获得该方法的任何有效结果。如果你做这样的事情
SELECT * FROM xxx WHERE username = {0} and password = {1}
试
SELECT COUNT(*) FROM xxx WHERE username = {0} and password = {1}
然后你得到和int值0或> 0回来验证。 但请向我们展示帮助更多指定的代码。
答案 1 :(得分:0)
这是猜测,因为你没有提供足够的信息来确定。
听起来你已经编写了自己的提供商,或者试图以某种方式规避它。
如果您无法登录,则代码会自动回退到默认提供程序,您仍然在web.config中找到了连接字符串。可能是visual studio'帮助'添加的默认连接字符串。这是一个mdf,这是当mdf不存在时它抛出的错误。
该数据库显然不存在,并且失败了该错误。
因此,您可能需要删除web.config中的提供程序或修复您自己的提供程序或修复您验证用户的方式。
答案 2 :(得分:0)
您正在使用成员资格提供程序正在尝试连接到SQL服务器 - 我猜这很可能是您尝试通过提供数据库文件名来使用本地sql express实例。
在这种情况下,如果数据库不存在,则提供程序会尝试创建数据库,并且帐户(运行代码的程序)可能需要对该文件夹具有读/写权限。或者你甚至可能没有在你的机器上安装sqlexpress等。
我建议您检查连接字符串并从那里尝试调试 - 例如,尝试连接到该数据库(远程/本地)或创建该数据库(以及所需的架构)(如果不存在)。将连接字符串更改为常规字符串(而不是提供文件名),依此类推......
有关创建成员资格提供程序所需的数据库和架构的更多帮助,请参阅此文章:http://www.asp.net/web-forms/tutorials/security/membership/creating-the-membership-schema-in-sql-server-cs
答案 3 :(得分:0)
我在这里发现了这个问题。我没有使用(或至少尝试使用)我的应用程序的任何成员资格提供程序,但我使用内置的Login控件作为我的登录页面。我正在处理提交按钮OnClick事件,该事件工作正常并在有效凭据时重定向但在无效时不重定向,并且我认为这是问题的根源,因为Login.Authenticate事件被触发但未处理。通过重新编写代码并使用我自己的提交表单而不是Login控件,它工作正常。