我试图在一个临时测试应用程序(用于调试)中打开一个Imanage文档( MS ),以便稍后复制到一个ActiveX控制项目中。弹出的错误是:
在0x7618851A (msvcrt.dll)处引发的异常( w3wp.exe: 0xC0000005: Access >违规读取位置0x09801000 )。 如果存在此异常的处理程序,则可以安全地继续该程序。
运行cmd.Execute行时会发生错误,我不确定为什么会收到错误。
using IManage;
using IMANEXTLib;
using System;
namespace WebApplication3
{
public partial class WebForm2 : System.Web.UI.Page
{
IManDatabase imanagedatabase;
IManDMS myDMS = new ManDMSClass();
protected void Page_Load(object sender, EventArgs e)
{
openImanageDoc("docNumber", "versionNumber", "server", "database", ReadOnly);
}
public void imanageLogin(string server, string database)
{
try
{
IManSession session = myDMS.Sessions.Add(server);
IManWorkArea oWorkArea = session.WorkArea;
session.TrustedLogin();
foreach (IManDatabase dbase in session.Databases)
{
if (dbase.Name == database)
{
imanagedatabase = dbase;
}
}
}
catch (Exception ex)
{
throw ex;
}
}
public void openImanageDoc(string docNo, string versionNo, string server, string database, bool isReadOnly = true)
{
IManDocument doc;
try
{
imanageLogin(server, database);
int iDocNo = int.Parse(docNo);
int iVersion = int.Parse(versionNo);
doc = imanagedatabase.GetDocument(iDocNo, iVersion);
openNRTDocument(ref doc, isReadOnly);
imanagedatabase.Session.Logout();
myDMS.Close();
}
catch (Exception Ex)
{
imanagedatabase.Session.Logout();
throw Ex;
}
finally
{
imanagedatabase = null;
myDMS = null;
}
}
public void openNRTDocument(ref IManDocument nrtDocument, Boolean isReadonly)
{
OpenCmd cmd = new OpenCmd();
ContextItems objContextItems = new ContextItems();
objContextItems.Add("NRTDMS", myDMS);
objContextItems.Add("SelectedNRTDocuments", new[] { (NRTDocument)nrtDocument.LatestVersion });
objContextItems.Add("IManExt.OpenCmd.Integration", false);
objContextItems.Add("IManExt.OpenCmd.NoCmdUI", true);
cmd.Initialize(objContextItems);
cmd.Update();
cmd.Execute();
}
}
}由于错误的性质,我假设这是一个配置问题,而不是代码错误,尽管我可能完全错了,因为我对编程非常陌生。
我发现w3wp.exe是由应用程序池创建的IIS进程,但除此之外,我不知道数字代码代表什么。任何帮助或建议都是非常感谢的。
发布于 2016-05-27 06:46:14
该错误是由OpenCmd实例引发的,因为它很可能试图访问资源,例如本地注册表设置。这在web应用程序中是不可能的,除非您在专有技术(如ActiveX (特定于Internet )中托管代码)。
实际上,在这里使用OpenCmd是不合适的。这些类型的命令(iManage "ICommand“实现)将用于安装了iManage FileSite或DeskSite客户端的常规Windows应用程序。这些命令都是所谓的扩展性COM库(iManExt.dll、iManExt2.dll等)的一部分,不应该在web应用程序中使用,或者至少要谨慎使用,因为它们可能不恰当地尝试访问注册表,就像您发现的那样,甚至可能显示输入Win32对话框。
对于一个web应用程序,你应该把自己限制在低级别的iManage COM库(IManage.dll)上。事实上,这就是iManage自己对自己的WorkSite Web应用程序所做的事情。
您应该做的可能是将您的openNRTDocument方法替换为如下所示:
// create a temporary file on your web server..
var filePath = Path.GetTempFileName();
// fetch a copy of the iManage document and save to the temporary file location
doc.GetCopy(filePath, imGetCopyOptions.imNativeFormat);在MVC web应用程序中,您只需返回一个FileContentResult,如下所示:
// read entire document as a byte array
var docContent = File.ReadAllBytes(filePath);
// delete temporary copy of file
File.Delete(filePath);
// return byte stream to web client
return File(stream, MediaTypeNames.Application.Octet, fileName);在Web窗体应用程序中,您可以这样做:
// set content disposition as appropriate - here example is for Word DOCX files
Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
// write file to HTTP content output stream
Response.WriteFile(filePath);
Response.End();https://stackoverflow.com/questions/37464825
复制相似问题