Asp.net负载平衡服务器错误

时间:2017-10-30 20:05:54

标签: c# asp.net azure load-balancing

我在asp.net应用程序上获得一个null引用错误,当它位于两个Azure负载平衡服务器上时。当我关闭一个时,错误消失了。查看调用堆栈时,没有一个真正的原因可以抛出空引用。我甚至在两台服务器上都设置了一个远程调试会话,没有合理的理由说明为什么我会得到一个空引用错误。我的直觉说它在一台服务器上工作正常,但在有两台服务器时却没有,所以它必须是负载平衡问题,我需要更改我的应用程序设置以包括负载平衡。这是否是应用程序设置需要改变的正常指示?如果是这样,需要改变什么?如果没有,我可以运行哪些其他诊断来使我的应用程序在群集上运行?

System.InvalidOperationException: Nullable object must have a value.
   at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
   at POS.Domain.Manager.GetCommodityList(Int32 locationID, DateTime delDate, Int32 ogID, VMUserProfile profile) in c:\Workspace\Ordering Portals\DanielBranch\POS.Domain\BLL\Manager.cs:line 1123
   at POS.UI.Controllers.OrderingController.GetCommodityList(Int32 locationID, String delDate, VMUserProfile userprofile) in c:\Workspace\Ordering Portals\DanielBranch\POS.UI\Controllers\OrderingController.cs:line 733
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.<BeginInvokeAction>b__1c()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Manager.cs

1 个答案:

答案 0 :(得分:0)

您的网站似乎是有状态的,这意味着您将信息存储在一台服务器上,这样如果用户被发送到另一台服务器,那么该信息就不会存在。例如,如果您正在使用进程内会话,则它们将仅存在于该服务器上。

幸运的是,Azure App Services中有一项功能允许用户每次都被发送回同一台服务器。

只需在应用程序设置下启用 ARR Affinity 设置即可。这将确保在每次请求时将用户发送回同一服务器。

Source

enter image description here