C# 标识示例在生产服务器上引发空引用异常

C# 标识示例在生产服务器上引发空引用异常,c#,asp.net-mvc,C#,Asp.net Mvc,有人能帮我解决这个问题吗?代码在我的电脑上运行正常,但当上传到生产服务器时,我出现以下错误: 对象引用未设置为对象的实例 描述:执行当前web请求期间发生未处理的异常。请查看堆栈跟踪以了解有关错误的更多信息以及错误在代码中的起源 异常详细信息:System.NullReferenceException:对象引用未设置为对象的实例 源错误: An unhandled exception was generated during the execution of the current web re

有人能帮我解决这个问题吗?代码在我的电脑上运行正常,但当上传到生产服务器时,我出现以下错误:

对象引用未设置为对象的实例

描述:执行当前web请求期间发生未处理的异常。请查看堆栈跟踪以了解有关错误的更多信息以及错误在代码中的起源

异常详细信息:System.NullReferenceException:对象引用未设置为对象的实例

源错误:

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.]
   IdentitySample.Controllers.<Register>d__17.MoveNext() +2542
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +144
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +84
   System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +143
   System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeAsynchronousActionMethod>b__36(IAsyncResult asyncResult) +23
   System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +112
   System.Web.Mvc.Async.<>c__DisplayClass48.<InvokeActionMethodFilterAsynchronouslyRecursive>b__41() +452
   System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +15
   System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +37
   System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +241
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +111
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +19
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +51
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +111
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288
在执行当前web请求期间生成了未处理的异常。有关异常的起源和位置的信息可以使用下面的异常堆栈跟踪来识别。
堆栈跟踪:
[NullReferenceException:对象引用未设置为对象的实例。]
IdentitySample.Controllers.d_u17.MoveNext()+2542
System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务任务)+144
System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务)+84
System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult)+143
System.Web.Mvc.Async.c__显示类37.b__36(IAsyncResult asyncResult)+23
System.Web.Mvc.Async.AsyncInvocationWithFilters.b__3f()+112
System.Web.Mvc.Async.c__显示类48.b__41()+452
System.Web.Mvc.Async.c__显示类33.b__32(IAsyncResult asyncResult)+15
System.Web.Mvc.Async.c__显示类2b.b__1c()+37
System.Web.Mvc.Async.c__显示类21.b__1e(IAsyncResult asyncResult)+241
System.Web.Mvc.Controller.b_u1d(IAsyncResult asyncResult,ExecuteCorerate innerState)+29
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)+111
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)+53
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)+19
System.Web.Mvc.MvcHandler.b_uu5(IAsyncResult asyncResult,ProcessRequestState innerState)+51
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)+111
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+606
System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔值&同步完成)+288

上传时是否遗漏了一些内容:(

如果不查看您的代码,很难进行诊断。但是,导致错误的MoveNext引用“表明”您没有获得到服务器的有效连接(SQL?),因此任何表对象或查询都不会生成并返回空对象。Hi@Sparky感谢您的回复,问题似乎是我的web配置文件中的连接字符串,在查看sql日志并看到没有登录尝试后,这是我的最后一个选项。所以我将其复制到记事本中,然后将其粘贴到配置文件中,现在可以正常工作。很高兴您让它正常工作。