如何在 Visual Studio 中本地调试文件权限问题?
我想调试 ASP.Net 网站,因为它尝试将文件写入目录。
当实际部署时,工作进程可能无法写入该文件,因此会抛出错误,这不是问题,因为我只想捕获错误,通知用户并继续。
当然,如果我在本地计算机上进行调试,那么我是管理员,并且有权写入该文件,因此我无法检查是否捕获了正确的错误,也无法单步执行如果我没有的话,看看哪里出了问题。处理这类事情有标准方法吗?
I want to debug an ASP.Net website as it attempts to write a file to a directory.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以用模拟方法替换文件写入方法,您可以修改模拟方法以返回所需的值(或引发适当的异常)。
研究模拟框架。
另一种解决方案可能是暂时删除这些文件夹的写入权限。您仍然拥有完全的控制权,因此您可以在完成测试后恢复权限。
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.