模拟在服务器路径上进行模拟的用户权限是什么?

我使用下面的示例,但我仍然有例外:

System.Security.Permissions.SecurityPermission 下面是技术支持人员的诊断信息:请求类型’System.Security.Permissions.SecurityPermission,mscorlib的权限

Admin表示用户凭证具有读写的完全权限

IntPtr userToken = IntPtr.Zero; bool success = External.LogonUser( "userID", "domain.com", "MyPassword", (int) AdvApi32Utility.LogonType.LOGON32_LOGON_INTERACTIVE, //2 (int) AdvApi32Utility.LogonProvider.LOGON32_PROVIDER_DEFAULT, //0 out userToken); if (!success) { throw new SecurityException("Logon user failed"); } using (WindowsIdentity.Impersonate(userToken)) { //Create a new GUID, extract the extension and create a new unique filename string strFileGUID = System.Guid.NewGuid().ToString(); string extension = Path.GetExtension(attachment.AttachmentFileName); string tempfilename = strFileGUID + extension; string path = "ServerPath"; //Open a filestream and write the contents of the file at server path FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write ); fs.Write(fileContent.Content, 0, fileContent.Content.Length); fs.Flush(); fs.Close(); } 

我可以帮忙解决这个问题吗?

您的代码不会以完全信任的forms运行,也无法获得正确的.Net权限来执行PInvoke或访问本地文件。 它与Windows用户权限无关。 链接的问题将使您开始.Net CAS – 代码访问安全性 – 为什么我的.NET应用程序中出现System.Security.Permissions.SecurityPermission错误? 。

一种简单的检查方法是在本地驱动器上本地运行您的应用程序 – 应该获得完全信任并且不再获得CASexception。