我使用了下面的示例,但我仍然有异常:
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();
}
当我被困在这个问题上时,你能帮忙吗?