List<string> ReturnDepList()
{
List<string> values = new List<string>();
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (MossTools m = new MossTools(Config.WebUrl))
{
//此行报错
values = m.getFieldWithPerson(Config.SendDepListName, m.GetUser(this.Application.User.LoginName).ID, "单位文件夹", "单位负责人", "单位联系人");
}
});
return values;
}
错误信息:
对象的当前状态使该操作无效。
System.InvalidOperationException: 对象的当前状态使该操作无效。
在 Microsoft.SharePoint.WebControls.SPControl.SPWebEnsureSPControl(HttpContext context)
在 Microsoft.SharePoint.WebControls.SPControl.GetContextWeb(HttpContext context)
在 Microsoft.Office.InfoPath.Server.SolutionLifetime.UserHost.GetCurrentUser()
在 Microsoft.Office.InfoPath.Server.SolutionLifetime.UserHost.<>c__DisplayClass1.<get_CurrentUser>b__0()
在 Microsoft.Office.InfoPath.Server.DocumentLifetime.OMExceptionManager.ExecuteOMCallWithExceptions(OMCall d, ExceptionFilter exceptionFilter)
在 Microsoft.Office.InfoPath.Server.DocumentLifetime.OMSecurityContext.ExecuteOMCall(Solution solution, SecurityLevel methodSecurityLevel, ExceptionFilter exceptionFilter, OMCall d)
在 Microsoft.Office.InfoPath.Server.DocumentLifetime.OMSecurityContext.ExecuteOMCall(Solution solution, SecurityLevel methodSecurityLevel, OMCall d)
在 Microsoft.Office.InfoPath.Server.SolutionLifetime.UserHost.get_CurrentUser()
在 Microsoft.Office.InfoPath.Server.SolutionLifetime.UserHost.<>c__DisplayClass4.<get_LoginName>b__3()
在 Microsoft.Office.InfoPath.Server.DocumentLifetime.OMExceptionManager.ExecuteOMCallWithExceptions(OMCall d, ExceptionFilter exceptionFilter)
在 Microsoft.Office.InfoPath.Server.DocumentLifetime.OMSecurityContext.ExecuteOMCall(Solution solution, SecurityLevel methodSecurityLevel, ExceptionFilter exceptionFilter, OMCall d)
在 Microsoft.Office.InfoPath.Server.DocumentLifetime.OMSecurityContext.ExecuteOMCall(Solution solution, SecurityLevel methodSecurityLevel, OMCall d)
在 Microsoft.Office.InfoPath.Server.SolutionLifetime.UserHost.get_LoginName()
在备忘备.FormCode.<>c__DisplayClass1.<ReturnDepList>b__0() 位置 C:\Documents and Settings\Administrator.SCALLY\My Documents\InfoPath 项目\SendDocument1\FormCode.cs:行号 1250
在 Microsoft.SharePoint.SPSecurity.CodeToRunElevatedWrapper(Object state)
在 Microsoft.SharePoint.SPSecurity.<>c__DisplayClass4.<RunWithElevatedPrivileges>b__2()
在 Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode)
在 Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param)
在 Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode)
在备忘备.FormCode.ReturnDepList() 位置 C:\Documents and Settings\Administrator.SCALLY\My Documents\InfoPath 项目\SendDocument1\FormCode.cs:行号 1246
在备忘备.FormCode.FormEvents_Loading(Object sender, LoadingEventArgs e) 位置 C:\Documents and Settings\Administrator.SCALLY\My Documents\InfoPath 项目\SendDocument1\FormCode.cs:行号 74
在 Microsoft.Office.InfoPath.Server.SolutionLifetime.FormEventsHost.<>c__DisplayClass6.<>c__DisplayClassa.<add_Loading>b__3()
在 Microsoft.Office.InfoPath.Server.Util.DocumentReliability.InvokeBusinessLogic(Thunk thunk)
在 Microsoft.Office.InfoPath.Server.SolutionLifetime.FormEventsHost.<>c__DisplayClass6.<add_Loading>b__2(Object sender, LoadingEventArgs e)
在 Microsoft.Office.InfoPath.Server.SolutionLifetime.FormEventsHost.<>c__DisplayClass34.<FireLoadingEvent>b__30()
在 Microsoft.Office.InfoPath.Server.DocumentLifetime.OMExceptionManager.CallFormCodeWithExceptionHandling(UserMessages userMessages, OMCall d)
已向服务器的 Windows 事件日志中添加了一个条目。
日志 ID:5337
将this.Application.User.LoginName提到RunWithElevatedPrivileges外面后,问题解决