仅当我从服务器(www.myapp1.com)运行我的应用程序时才会出现此错误。该应用程序从visual studio运行良好。我总是将我的代码部署到服务器,我只是构建并复制新的DLL,一切正常。
这是实际错误
Object reference not set to an instance of an object.
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:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
CRM.Web.Login.getBusinessRuleId(Int32 clientID, Int32 ruleId) +768
CRM.Web.Login.setRulexception() +1217
CRM.Web.Login.DoAuthenticate(SecUser user) +3489
CRM.Web.Login.btnSubmit_click(Object sender, EventArgs e) +626
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +154
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3803
这些功能都是我没有创建的新功能。我知道这是一个广泛的错误,但我不确定为什么会出现这个错误。
以下是我的功能
public List<BusinessRule> getBusinessRuleId(int clientID, int ruleId)
{
System.Diagnostics.Debug.WriteLine("get business rule client id = " + clientID + " rule ID = " + ruleId);
List<BusinessRule> businessRuleArr = new List<BusinessRule>();
BusinessRuleManager businessRuleManager = new BusinessRuleManager();
businessRuleArr = businessRuleManager.GetBusinessRuleThread(clientID,ruleId);
for (var i = 0; i < businessRuleArr.Count; i++)
{
XElement ruleXML = XElement.Parse(businessRuleArr[i].RuleXML.ToString());
using (RuleHelper ruleHelper = new RuleHelper())
{
XElement conditionLapseTime = ruleHelper.GetElement(ruleXML, "LapseTime");
businessRuleArr[i].Description = conditionLapseTime.Element("value").Value;
XElement conditionLapseTimeType = ruleHelper.GetElement(ruleXML, "LapseTimeType");
businessRuleArr[i].RuleXML = conditionLapseTimeType.Element("value").Value;
}
}
return businessRuleArr;
}
public void setRulexception()
{
ucAllUserLeads userGetClaim = new ucAllUserLeads();
List<LeadView> leadView = new List<LeadView>();
leadView = userGetClaim.getLeadList();
int clientID = Convert.ToInt32(Session["ClientId"]);
int userID = Convert.ToInt32(Session["UserId"]);
int claimId;
System.Diagnostics.Debug.WriteLine("set rule exception userID, - " + userID);
for (int i = 0; i < leadView.Count; i++)
{
claimId = leadView[i].ClaimID;
System.Diagnostics.Debug.WriteLine("set rule exception claimID, - " + claimId);
if (claimId != 0) {
int progressId = getProgressId(claimId);
DateTime progressDate = progressClaimRecievedData(claimId);
if (progressId != 0)
{
List<int> ruleId = getRuleId(progressId);
for (var j = 0; j < ruleId.Count; j++)
{
if (ruleId.Count != 0)
{
List<BusinessRule> businessRuleArr = new List<BusinessRule>();
businessRuleArr = getBusinessRuleId(clientID, ruleId[j]);
for (var k = 0; k < businessRuleArr.Count; k++)
{
int timeInterval = getTimeFlag(businessRuleArr[k].RuleXML, businessRuleArr[k].Description);
TimeSpan timeDiff = DateTime.Now - progressDate;
if ((timeDiff.Days * 24 + timeDiff.Hours) >= timeInterval)
{
int checkstate = checkInsertable(businessRuleArr[k].BusinessRuleID, clientID, userID, claimId);
if (checkstate == 0)
{
insertRuleException(businessRuleArr[k].BusinessRuleID, clientID, userID, claimId);
}
if (checkstate == 1)
{
updateRuleException(businessRuleArr[k].BusinessRuleID, clientID, userID, claimId);
}
}
}
}
}
}
}
}
}
public void DoAuthenticate(CRM.Data.Entities.SecUser user)
{
string url = null;
string userData = null;
List<int> roleActions = null;
System.Diagnostics.Debug.WriteLine("Do Authenticate -" + user.UserName);
Session["UserId"] = user.UserId;
Session["UserName"] = user.UserName;
Session["RoleId"] = user.SecRole.RoleId.ToString();
// 201307-29
Session["ClientId"] = user.ClientID;
if (user.Client.Count > 0)
{
Session["ClientShowTask"] = user.Client == null ? true : (user.Client.FirstOrDefault().isShowTasks ?? true);
}
else
{
Session["ClientShowTask"] = true;
}
userData = string.Format("{0}|{1}|{2} {3}|{4}", user.SecRole.RoleName, user.SecRole.RoleId, user.FirstName, user.LastName, user.Email);
System.Diagnostics.Debug.WriteLine("User role -" + user.SecRole.RoleName);
var ticket = new FormsAuthenticationTicket
(
1,
user.UserId.ToString(),
DateTime.Now,
DateTime.Now.AddMinutes(120),
true,
userData, //(user.SecRole.RoleName + "|" + user.SecRole.RoleId.ToString()),
FormsAuthentication.FormsCookiePath
);
string encryptedTicket = FormsAuthentication.Encrypt(ticket);
Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket));
Session["rolePermission"] = resRolePermission = SecRoleModuleManager.getRolePermission(user.SecRole.RoleId).ToList();
// get role actions
if (user.RoleId != (int)UserRole.Administrator)
{
using (ActionManager repository = new ActionManager())
{
roleActions = repository.GetActions((int)user.ClientID, (int)user.RoleId);
Session["roleActions"] = roleActions;
}
}
//if (user.SecRole.RoleId == (int)UserRole.Adjuster)
// url = "~/Protected/Intake/form.aspx";
//else
if (Request.QueryString["url"] != null)
{
url = Request.QueryString["url"].ToString();
}
else
{
url = FormsAuthentication.DefaultUrl;
Session["Count"] = null;
formatException();
setRulexception();
setGlobalSession();
Thread thread = new Thread(delegate()
{
workerObject.DoWork();
});
//ThreadPool.QueueUserWorkItem(new WaitCallback(workerObject.DoWork), leadView, testse);
// workerThread = new Thread(workerObject.DoWork);
thread.Start();
}
Response.Redirect(url);
}