Why iis host application do not let log in?

2019-09-21 23:39发布

I have hosted my applciation to the IIS -7 and it browses proper but it doest let me log in now, desipte i have checked it has a correct connection string, it throws error at my log page

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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...

标签: c# asp.net iis
1条回答
Animai°情兽
2楼-- · 2019-09-22 00:21
 SqlParameter[] arrParams = new SqlParameter[0];
 _userDetails = Data.GetSQLQueryResults(sqlQuery, 0, arrParams);

You are passing arrParams with zero elements in it, Your query might expect some parameter to return the result. There is a chance that you have null for _userDetails as you are getting now. You can prevent the exception by putting check for null on _userDetails

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

}

To find out exact cause

if (_userDetails != null)
{
   //No data table returned
   if( _userDetails.Rows.Count != 0)
   {
        //No record found
   }
}
查看更多
登录 后发表回答