【问题标题】:Getting MicrosoftOnlineException when website is hosted in IIS当网站托管在 IIS 中时出现 MicrosoftOnlineException
【发布时间】:2015-06-26 12:41:50
【问题描述】:

有一个从 asp.net 调用的 powershell 脚本。 powershell 基本上连接到 Windows Azure 模块。

当我从 VS 调试 asp.net 时,它托管在 IIs-express 中,并且 powershell 脚本按预期运行。 但是当网站托管在 IIS 中时,会抛出以下异常

System.Management.Automation.InvalidPowerShellStateException occurred
  HResult=-2146233087
  Message=Microsoft.Online.Administration.Automation.MicrosoftOnlineException: Exception of type 'Microsoft.Online.Administration.Automation.MicrosoftOnlineException' was thrown.
Microsoft.Online.Administration.Automation.MicrosoftOnlineException: You must call the Connect-MsolService cmdlet before calling any other cmdlets.

Server stack trace: 
   at Microsoft.Online.Administration.Automation.BecWebServiceInspector.BeforeSendRequest(Message& request, IClientChannel channel)
   at System.ServiceModel.Dispatcher.ImmutableClientRuntime.BeforeSendRequest(ProxyRpc& rpc)
   at System.ServiceModel.Channels.ServiceChannel.PrepareCall(ProxyOperationRuntime operation, Boolean oneway, ProxyRpc& rpc)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at IProvisioningWebService.GetRoleByName(GetRoleByNameRequest request)
   at ProvisioningWebServiceClient.GetRoleByName(GetRoleByNameRequest request)
System.Management.Automation.ParameterBindingException: Cannot bind parameter 'RoleObjectId' to the target. Exception setting "RoleObjectId": "Object reference not set to an instance of an object." ---> System.Management.Automation.SetValueInvocationException: Exception setting "RoleObjectId": "Object reference not set to an instance of an object." ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at lambda_method(Closure , Object , Object )
   at System.Management.Automation.ReflectionParameterBinder.BindParameter(String name, Object value)
   --- End of inner exception stack trace ---
   at System.Management.Automation.ReflectionParameterBinder.BindParameter(String name, Object value)
   at System.Management.Automation.ParameterBinderBase.BindParameter(CommandParameterInternal parameter, CompiledCommandParameter parameterMetadata, ParameterBindingFlags flags)
   --- End of inner exception stack trace ---
   at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input, Hashtable errorResults, Boolean enumerate)
   at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)
   at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)

  Source=ManagementConsoleV2
  StackTrace:
       at ManagementConsoleV2.Structures.Lync_Online.PowershellWrapper.RunPowerShellScript(String userName, String plainPassword, PowerShellScriptType powerShellScriptType) in c:\Dev Team\Sameer\Trunk\Web\ManagementConsoleV2\Structures\Lync Online\PowershellWrapper.cs:line 64
  InnerException: 

当应用程序在 IIS-express 中运行时,进程以 32 位模式运行。我还在 IIS 的 32 位/64 位模式线程池中托管了该应用程序,但两次都出现了相同的错误。

【问题讨论】:

    标签: powershell iis office365


    【解决方案1】:

    在 IIS 中 转到您的站点设置为在其中运行的应用程序线程池的高级设置并设置 加载用户个人资料:true

    【讨论】:

      猜你喜欢
      • 2016-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多