我在用Word.Application、Excel.Application将Word、Excel转换至Html出错错误,如下:*********************************************************************************
拒绝访问。 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.UnauthorizedAccessException: 拒绝访问。 ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user. To grant ASP.NET write access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  Stack Trace: 
************************************************************************************在 Web.config 中配置 <identity impersonate="true"/> 上传到服务器,在转换时提示输入用户名、密码,真是头疼。
请问哪位高手有没有一种更好了方法可以解决这个问题。

解决方案 »

  1.   

    To grant ASP.NET write access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.若要授予 ASP.NET 对目录的写访问权,请在资源管理器中右击该目录,选择“属性”,然后选择“安全”选项卡。单击“添加”添加适当的用户或组。突出显示 ASP.NET 帐户,选中所需访问权限对应的框。
      

  2.   

    object oMissing =System.Reflection.Missing.Value;
    Word.Document mydoc;
    Word.Application word_app=new Word.ApplicationClass();
    word_app.Visible=true;
    word_app.Documents.Add(ref oMissing,ref oMissing,ref oMissing,ref oMissing);
    mydoc=word_app.ActiveDocument;
    object FileName=MapPath("../files/")+"11.doc";
    word_app.Documents.Open(ref FileName,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing);object missing = System.Reflection.Missing.Value; 
    object fileName = MapPath("../files/22.html"); 
    object Format = (int)Word.WdSaveFormat.wdFormatHTML; 
    mydoc.SaveAs(ref fileName, ref Format,ref missing, ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing, ref missing,ref missing,ref missing,ref missing,ref missing,ref missing); 
    mydoc.Close(ref oMissing,ref oMissing,ref oMissing);
    word_app.Quit(ref oMissing,ref oMissing,ref oMissing);
      

  3.   

    需要将ASPNET的用户添加到Office组件中..才能有写的权限..具体做法:执行“ DCOMCNFG”命令...选择“应用程序”页的“Microsoft Execl 应用程序”—>“属性”—>“安全性”—>三个选项都选“使用自定义访问权限”...添加“Everyone”权限。
      

  4.   

    to bingbingcha 
       太感谢了,不过在转换Word时出现错误,提示“内存不足,请现在保存文档”,在转换Excel时一切正常