DSOFile 和中等信任

发布于 2024-09-10 11:25:43 字数 740 浏览 6 评论 0原文

(C#,ASP.NET 3.5 环境)我使用 Microsoft 的 DSOFile.dll 来计算 Word 文档(.doc 格式)中的页数。当我将应用程序部署到中等信任环境 (GoDaddy) 时,我遇到了安全异常。我将 Web 服务范围缩小到导致问题的行,看起来它发生在以下代码块中:

DSOFile.SummaryProperties props;
       DSOFile.OleDocumentPropertiesClass mDoc = new DSOFile.OleDocumentPropertiesClass();
    mDoc.Open(ActualPath, true, DSOFile.dsoFileOpenOptions.dsoOptionDefault);
    props = mDoc.SummaryProperties;
    Pages = props.PageCount;

只要第三行 (mDoc.Open) 在那里,它就会给我安全异常。注释掉后,该文件会正常运行,虽然它不提供 .doc 文件的计数,但它会计算我为其设置案例的其他类型的文件。我认为这可能与绝对路径与相对路径有关,但后来我注意到,即使在本地调试时(在将应用程序中的信任级别设置为“中”之后),它也会在没有实际运行任何方法的情况下崩溃,并且只是由于该原因线在那里。因此,显然中等信任和这种文件 I/O 方法不起作用。对于我的 Web 服务(通过 SOAP 和 JSON)以及我创建的测试 ASP.NET 页面,此行为是相同的。有谁知道在中等信任环境中实现我想要做的事情的替代方法?

(C#, ASP.NET 3.5 Environment) I'm using Microsoft's DSOFile.dll for counting the pages in a word document (.doc format). When I deployed my application to a medium trust environment (GoDaddy) I got a security exception. I narrowed my web service down to the line which is causing the problem, and it looks like it takes place in the following code block:

DSOFile.SummaryProperties props;
       DSOFile.OleDocumentPropertiesClass mDoc = new DSOFile.OleDocumentPropertiesClass();
    mDoc.Open(ActualPath, true, DSOFile.dsoFileOpenOptions.dsoOptionDefault);
    props = mDoc.SummaryProperties;
    Pages = props.PageCount;

It gives me the security exception so long as the third line (mDoc.Open) is in there. When commented out, the file acts normally, and while it doesn't give counts for .doc files, it does count the other types of files i have cases set up for. I thought it may have something to do with Absolute vs Relative paths, but then I noticed that even when debugging locally (after setting my trust level in my app to Medium) it crashed without actually running any methods, and simply as a result of that line being in there. So, obviously Medium Trust and this method of file I/O don't work. This behavior is the same for my web service (through SOAP and JSON) as well as on a test ASP.NET page I created. Does anyone know of an alternative method for achieving what I want to do in a Medium Trust environment?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文