问题陈述:通过WCF服务对登录凭据进行身份验证。基于登录ID身份验证,在另一个控制器中将“客户ID”分配给Session的调用方法给出了空引用异常。我在做什么错?WCF服务代码:在这里,我能够验证用户并根据登录ID获取客户详细信息。public bool IsValid(LoginDC objLoginDC){ try { var result = dbEntity.CustomerUsers.FirstOrDefault(m => m.LoginID == objLoginDC.LoginID && m.Password == objLoginDC.Password); if (result != null) { return true; } else { return false; } } catch { return false; }}public IEnumerable<CustomerUserDC> GetLoginCustomerUserDetails(LoginDC objLoginDC){ return (from tu in dbEntity.CustomerUsers.AsEnumerable() where tu.LoginID == objLoginDC.LoginID && tu.Password == objLoginDC.Password select new CustomerUserDC { CustomerID = tu.CustomerID, UserID = tu.UserID, Name = tu.Name }).ToList();}登录控制器:在这里,我叫“登录身份验证”并获取WCF的“客户详细信息”方法。我可以从WCF中获取值,但无法为会话分配值。public ActionResult Index(LoginModel loginModel, string returnUrl){ if (ModelState.IsValid) { objLoginDC.LoginID = loginModel.LoginID; objLoginDC.Password = loginModel.Password; if (objSvcMasterConfig.IsValid(objLoginDC)) { var varLoginCustomerUserDetails=objSvcMasterConfig.GetLoginCustomerUserDetails(objLoginDC); objGenController.GlobalSessionCustomerUserDetails(varLoginCustomerUserDetails); FormsAuthentication.SetAuthCookie(objLoginDC.LoginID, objLoginDC.RememberMe); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", "The Log In ID or Password provided is incorrect."); } } return View(loginModel);}总经理:在这里,我无法分配从Login Controller中的WCF服务获取的值,因为未将对象引用设置为General Controller中的对象异常的实例。public void GlobalSessionCustomerUserDetails(dynamic varLoginCustomerUserDetails){ Session["TempCustDetails"] = varLoginCustomerUserDetails[0].LoginID;} 最佳答案 尝试将返回类型更改为List ...公共列表GetLoginCustomerUserDetails(LoginDC objLoginDC)关于c# - 在MVC中,将值分配给 session ,从而将对象引用设置为对象异常的实例,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22835626/
10-12 12:58