首页 \ 问答 \ 如何拒绝与CAS断言?(How to deny Assert with CAS?)

如何拒绝与CAS断言?(How to deny Assert with CAS?)

在这段代码中,我希望禁止ReadFileSystem方法断言文件系统的权限。

我预计这会抛出fileIo.Assert(),但它不会。 为什么?

using System.Security.Permissions;
static void Main(string[] args)
{
    var fileIo = new FileIOPermission(PermissionState.Unrestricted);
    var secuPerm = new SecurityPermission(SecurityPermissionFlag.Assertion);
    PermissionSet set = new PermissionSet(PermissionState.Unrestricted);
    set.AddPermission(fileIo);
    set.AddPermission(secuPerm);
    set.Deny();
    ReadFileSystem();
    Console.Read();
}

private static void ReadFileSystem()
{
    var fileIo = newFileIOPermission(PermissionState.Unrestricted);
    fileIo.Assert();

    DirectoryInfo dir = new DirectoryInfo("C:/");
    dir.GetDirectories();
}

更新

这里有很好的CAS链接: http//blogs.msdn.com/shawnfa/archive/2004/08/25/220458.aspx


In this code, I'd like the ReadFileSystem method to be forbidden to Assert a permission on the filesystem.

I expected this will throw at fileIo.Assert(), but it doesn't. Why?

using System.Security.Permissions;
static void Main(string[] args)
{
    var fileIo = new FileIOPermission(PermissionState.Unrestricted);
    var secuPerm = new SecurityPermission(SecurityPermissionFlag.Assertion);
    PermissionSet set = new PermissionSet(PermissionState.Unrestricted);
    set.AddPermission(fileIo);
    set.AddPermission(secuPerm);
    set.Deny();
    ReadFileSystem();
    Console.Read();
}

private static void ReadFileSystem()
{
    var fileIo = newFileIOPermission(PermissionState.Unrestricted);
    fileIo.Assert();

    DirectoryInfo dir = new DirectoryInfo("C:/");
    dir.GetDirectories();
}

Update

Great link here on CAS : http://blogs.msdn.com/shawnfa/archive/2004/08/25/220458.aspx


原文:https://stackoverflow.com/questions/604450
更新时间:2023-12-31 19:12

最满意答案

尝试使用ReadConsoleInput以避免cooked模式,并使用GetNumberOfConsoleInputEvents来避免阻塞。


Try ReadConsoleInput to avoid cooked mode, and GetNumberOfConsoleInputEvents to avoid blocking.

相关问答

更多
  • 你的问题听起来有点困惑。 select()用于阻塞,直到输入可用。 但是你用正常的文件读取功能(如read , fread , fgetc等)来做实际的读取。 这是一个简单的例子。 它阻塞,直到stdin至少有一个可供阅读的字符。 但是,当然,除非您将终端更改为某种未烹饪的模式,否则它会阻塞,直到您按下回车键,当任何键入的字符被刷新到文件缓冲区(从某个终端缓冲区中)时。 #include #include int main(void) { fd_s ...
  • 如上所述,您可以使用sigaction来捕获ctrl-c,或者select捕获任何标准输入。 但是请注意,使用后一种方法,您还需要设置TTY,使其处于一个字符的时间,而不是一时一行的模式。 后者是默认值 - 如果您输入一行文本,则不会将其发送到正在运行的程序的stdin,直到您按Enter键。 您需要使用tcsetattr()函数关闭ICANON模式,也可能会禁用ECHO。 从内存中,当程序退出时,您还必须将终端设置为ICANON模式! 只是为了完整,这里有一些我刚刚敲下的代码(nb:没有错误检查!),它设 ...
  • 不,输入设备模拟非常特定于平台,即使在单一平台上也很挑剔。 它不是用于任何目的的强大技术,因此您将找不到好的库来实现它。 一旦掌握了基本API,最困难的部分就是让设备看起来更加逼真。 您希望逐渐鼠标移动更新以中等高频率发送,就像鼠标一样,以及点击和按键之间的合理延迟。 执行事件的时间轴和执行基本几何可能会得到像SDL这样的游戏库的帮助。 如果您忽略计时,操作系统可能会扼杀鼠标移动,去抖动按钮,重新排列动作和点击的顺序,在使用触控板时忽略按键等等。我差不多10年前写过这样一个工具。 No, input dev ...
  • 问题是游戏正在通过DirectX运行,这阻止了虚拟键盘敲击。 通过从sys系统中直接渲染游戏,它避免了所有的一起使用并且工作得很好:) The problem was that the game was running though DirectX, which prevented virtual keyboard strokes. By rending the game right from the sys, it avoided directx all together and worked fine ...
  • 答案由Hans Passant提供( https://stackoverflow.com/users/17034/hans-passant ): 此事件公开了在物理键盘上键入的字符: http : //msdn.microsoft.com/en-us/library/windows.ui.core.corewindow.characterreceived.aspx Answer provided by Hans Passant (https://stackoverflow.com/users/17034/h ...
  • 正如hyde的帖子中所述,我可以使用Lua包装器为ncurses获取输入。 除此之外,我可以将其功能用于我的代码的其他部分,无论如何我将自己编程。 As stated in the comments of my post by hyde, I can use a Lua wrapper for ncurses to get input. In addition to this, I can use its features for some other parts of my code that I was ...
  • 我设法以某种方式解决我使用此功能的特定问题 extern GetAsyncKeyState 它有一些选项可以在按下按键时返回给定值,也可以选择自上次调用函数后按下该按键时的值 - 所以我在程序开始时调用该函数一次,然后检查自那时起是否调用了该函数。 然而,使用这种方法时存在很多问题,所以我会检查其他人很快提出的问题,并可能会发布更好的解决方案。 I managed to somehow solve my particular problem using this function extern GetAsy ...
  • 尝试一下: import os from subprocess import Popen, PIPE cmd = r"C:\LTR_STRUC\LTR_STRUC_1_1.exe" app = Popen(cmd, stdin=PIPE, shell=True) app.stdin.write("y" + os.linesep) ... 此外,如果您想要响应提示,您也可以PIPE stdout并通过以下方式访问它: app.stdout.read() 参考: https : //docs.python ...
  • 显然是跳过输入操作的原因很可能是(这意味着,忽略了一个bugsy XCode IDE的可能特性),你之前已经执行了一些输入并在输入缓冲区中留下了一个换行符 。 要解决这个问题,请确保在逻辑上应该消耗输入行的每个输入操作之后清空了输入缓冲区。 一种简单的方法是始终将getline用于string ,然后如果要将数字规范转换为数字类型,则使用例如istringstream 。 干杯&hth。, The reason that the input operation apparently is skipped, ...
  • 尝试使用ReadConsoleInput以避免cooked模式,并使用GetNumberOfConsoleInputEvents来避免阻塞。 Try ReadConsoleInput to avoid cooked mode, and GetNumberOfConsoleInputEvents to avoid blocking.

相关文章

更多

最新问答

更多
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • 电脑高中毕业学习去哪里培训
  • 电脑系统专业就业状况如何啊?
  • IEnumerable linq表达式(IEnumerable linq expressions)
  • 如何在Spring测试中连接依赖关系(How to wire dependencies in Spring tests)
  • Solr可以在没有Lucene的情况下运行吗?(Can Solr run without Lucene?)
  • 如何保证Task在当前线程上同步运行?(How to guarantee that a Task runs synchronously on the current thread?)
  • 在保持每列的类的同时向数据框添加行(Adding row to data frame while maintaining the class of each column)
  • 的?(The ? marks in emacs/haskell and ghc mode)
  • 一个线程可以调用SuspendThread传递自己的线程ID吗?(Can a thread call SuspendThread passing its own thread ID?)
  • 延迟socket.io响应,并“警告 - websocket连接无效”(Delayed socket.io response, and “warn - websocket connection invalid”)
  • 悬停时的图像转换(Image transition on hover)
  • IIS 7.5仅显示homecontroller(IIS 7.5 only shows homecontroller)
  • 没有JavaScript的复选框“关闭”值(Checkbox 'off' value without JavaScript)
  • java分布式框架有哪些
  • Python:填写表单并点击按钮确认[关闭](Python: fill out a form and confirm with a button click [closed])
  • PHP将文件链接到根文件目录(PHP Linking Files to Root File Directory)
  • 我如何删除ListView中的项目?(How I can remove a item in my ListView?)
  • 您是否必须为TFS(云)中的每个BUG创建一个TASK以跟踪时间?(Do you have to create a TASK for every BUG in TFS (Cloud) to track time?)
  • typoscript TMENU ATagParams小写(typoscript TMENU ATagParams lowercase)
  • 武陟会计培训类的学校哪个好点?
  • 从链接中删除文本修饰(Remove text decoration from links)