C# 为什么iis主机应用程序不允许登录?
我已经托管了我的IIS-7应用程序,它可以正常浏览,但它现在不允许我登录,如果我检查了它是否有正确的连接字符串,它会在我的日志页上抛出错误 描述:执行当前web请求期间发生未处理的异常。请查看堆栈跟踪以了解有关错误的更多信息以及错误在代码中的起源C# 为什么iis主机应用程序不允许登录?,c#,asp.net,iis,C#,Asp.net,Iis,我已经托管了我的IIS-7应用程序,它可以正常浏览,但它现在不允许我登录,如果我检查了它是否有正确的连接字符串,它会在我的日志页上抛出错误 描述:执行当前web请求期间发生未处理的异常。请查看堆栈跟踪以了解有关错误的更多信息以及错误在代码中的起源 Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error: Line
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...
如果传递的arrParams中包含零个元素,则查询可能希望某个参数返回结果。您现在获得的用户详细信息可能为空。您可以通过在_userDetails上检查null来防止异常
if (_userDetails != null && _userDetails.Rows.Count != 0)
{
}
查明确切原因
if (_userDetails != null)
{
//No data table returned
if( _userDetails.Rows.Count != 0)
{
//No record found
}
}
你忘了告诉我们它犯了什么错误。当我使用用户名、密码登录时,它在第8行出现X错误。错误非常清楚,
对象引用未设置为对象的实例。因为它发生在第98行,所以\u userDetails
或行
为null
。我猜\u userDetails
是null
。在这种情况下,Data.GetSQLQueryResults()
方法被破坏,因为返回null
是个坏主意。不管怎样,这不是你的问题所在。您需要修复该函数(可能还有许多其他代码)以报告它遇到的问题,以便确定问题所在。当我直接运行它时,我的意思是不从IIS浏览,从visual studio c+f5运行,它工作正常,而且我的函数setUserData返回void。您真的没有在听。问题完全超出了您在问题中提供的信息范围。在不同的环境下,它在其他地方起作用并不重要。是否可以将调试器附加到它并不重要。您的Data.GetSQLQueryResults()
函数正在返回null
,您认为它永远不会返回。要么假设是错误的(在尝试使用它之前需要检查null
值),要么函数中有错误。您需要在应用程序中添加错误捕获和日志记录,以便查看更多运行时信息。
if (_userDetails != null)
{
//No data table returned
if( _userDetails.Rows.Count != 0)
{
//No record found
}
}