什么是模拟在服务器路径写入文件的用户权限

本文关键字:文件 用户 权限 路径 模拟 服务器 什么 | 更新日期: 2023-09-27 18:33:02

我使用了下面的示例,但我仍然有异常:

System.Security.Permissions.SecurityPermission 下面提供了技术支持人员的诊断信息:请求类型'System.Security.Permissions.SecurityPermission, mscorlib

管理员说用户凭据具有读取和写入的完全权限

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(); 
} 

你能帮忙吗,因为我被困在这个问题上?

什么是模拟在服务器路径写入文件的用户权限

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

一种简单的检查方法是在本地驱动器的相关计算机上本地运行应用程序 - 应该获得完全信任,并且不再获得 CAS 异常。