【发布时间】:2013-06-27 10:32:25
【问题描述】:
当 Visual Studio 在管理员帐户下运行时,以下代码可以正常工作。 但是当VS在非特权账户下运行时,Save()方法会抛出UnauthorizedAccessException,但是在这种情况下我很不明白为什么Demand()不会抛出SecurityException。
public void SetLoggingLevel(string loggerRuleName, LoggingLevel loggingLevel)
{
foreach (XElement loggerRule in GetLoggerElements().Where(loggerRule => CompareWithLoggerRule(loggerRuleName, loggerRule)))
{
loggerRule.SetAttributeValue("minlevel", loggingLevel.ToString());
var permission = new FileIOPermission(FileIOPermissionAccess.Write, Source);
permission.Demand();
_configFile.Save(Source); //Writing to the xml-file
return;
}
throw new RuleNotFoundException("The rule not found.");
}
【问题讨论】:
-
你尝试过使用 permission.Assert() 吗?
-
试过了。同样的结果:UnauthorizedAccessException
标签: c# .net security code-access-security