[英]How can I locally debug file permission issues in Visual Studio?
I want to debug an ASP.Net website as it attempts to write a file to a directory. 我想调试ASP.Net网站,因为它试图将文件写入目录。
When actually deployed this file would possibly not be writeable by the worker process so an error would be thrown, this is not a problem as I just want to catch the error, inform the user and move on. 实际部署时,该文件可能无法由工作进程写入,因此会引发错误,这不是问题,因为我只是想抓住错误,通知用户并继续前进。
Of course, if I'm debugging on my local machine then I'm an administrator and I have permission to write to the file, so I can't check that I've trapped the correct errors and I can't step through an see where it goes wrong if I haven't. 当然,如果要在本地计算机上调试,则我是管理员,并且有权写入该文件,因此无法检查是否已捕获正确的错误,也无法逐步执行如果没有的话,看看哪里出了问题。 Is there a standard approach to this sort of thing?
是否有处理这种事情的标准方法?
You could replace the file writing methods with mock methods that you can modify to return the desired values (or raise the appropriate exception). 您可以用模拟方法代替文件写入方法,您可以修改这些模拟方法以返回所需的值(或引发适当的异常)。
Look into mocking frameworks. 查看模拟框架。
Another solution could be to temporarily remove your write permissions from those folders. 另一种解决方案是从这些文件夹中临时删除您的写权限。 You still have full control so you can put the rights back after you've finished testing.
您仍然拥有完全控制权,因此可以在完成测试后放回权利。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.