2012-07-10 41 views
-3

我已经托管我的应用程序到IIS -7,它浏览正确,但它现在让我登录,desipte我已检查它有一个正确的连接字符串,它会在我的日志页上引发错误为什么iis主机应用程序不允许登录?

描述:An在执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关该错误的更多信息以及源代码的位置。

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. 

Source Error: 


Line 96:   SqlParameter[] arrParams = new SqlParameter[0]; 
Line 97:   _userDetails = Data.GetSQLQueryResults(sqlQuery, 0, arrParams); 
Line 98:   if (_userDetails.Rows.Count != 0) 
Line 99:   { 
Line 100:   _userAccountID = _userDetails.Rows[0]["UserAccountID"].ToString(); 


Source File: d:\Projects\June 20\CorrDefensev2\App_Code\UserInfo.cs Line: 98 

Stack Trace: 

[NullReferenceException: Object reference not set to an instance of an object.] 
    UserInfo.setUserData(MembershipUser membershipUser) in d:\Projects\June 20\CorrDefensev2\App_Code\UserInfo.cs:98 
    UserInfo..ctor(String username) in d:\Projects\June 20\CorrDefensev2\App_Code\UserInfo.cs:76 
    Account_Login.Login1_LoggingIn(Object sender, LoginCancelEventArgs e) in d:\Projects\June 20\CorrDefensev2\MyPublic\Login.aspx.cs:76 
    System.Web.UI.WebControls.Login.OnLoggingIn(LoginCancelEventArgs e) +115 
    System.Web.UI.WebControls.Login.AttemptLogin() +85 
    System.Web.UI.WebControls.Login.OnBubbleEvent(Object source, EventArgs e) +101 
    System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37 
    System.Web.UI.WebControls.ImageButton.OnCommand(CommandEventArgs e) +125 
    System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +177 
    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) +5563 



the solution: all i had to use sql server authentication that is a connection string in web.config with the username, password, and it works fantastic... 
+0

你忘了告诉我们_what_错误时抛出。运行时值是什么时候抛出的。 – David 2012-07-10 10:06:25

+0

当我用某个用户名,密码登录时,它在第8行出现throwsx错误。 – NoviceToDotNet 2012-07-10 10:07:37

+1

错误非常明显,“对象引用未设置为对象的实例”。由于它发生在第98行,因此'_userDetails'或'Rows'都是'null'。我的猜测是'_userDetails'是'null'。在这种情况下,您的'Data.GetSQLQueryResults()'方法被破坏,因为返回'null'是一个坏主意。无论哪种方式,这不是你的问题所在。您需要修复该功能(可能还有很多其他代码)来报告遇到的问题,以便确定哪些问题。 – David 2012-07-10 10:10:07

回答

0
SqlParameter[] arrParams = new SqlParameter[0]; 
_userDetails = Data.GetSQLQueryResults(sqlQuery, 0, arrParams); 

你传入arrParams在它零个元素,您的查询可能会想到一些参数,返回结果。您现在正在获取_userDetails的空值。您可以防止异常通过把检查空上_userDetails

if (_userDetails != null && _userDetails.Rows.Count != 0) 
{ 

} 

要找出确切病因

if (_userDetails != null) 
{ 
    //No data table returned 
    if(_userDetails.Rows.Count != 0) 
    { 
     //No record found 
    } 
} 
相关问题