在IIS中托管网站时获取MicrosoftOnlineException

时间:2015-06-25 11:03:32

标签: powershell iis office365

有一个从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位模式线程池中托管了该应用程序,但两次都得到相同的错误。

1 个答案:

答案 0 :(得分:1)

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