PPT/Word文件未从IIS服务器下载

本文关键字:IIS 服务器 下载 Word 文件 PPT | 更新日期: 2023-09-27 18:24:06

我已经开发了MVC4应用程序并托管在IIS服务器上。在应用程序中,我创建了PPT和Word的模板下载。它在本地运行得很好,但在IIS服务器上托管后,我无法下载它。请为我提供解决方案&其设置其对服务器的组件服务或其他事物的要求。我的代码是:控制器:

 public ActionResult DownloadFile(GlobalDashboardModel objGlobalDashboard)
 {
    //string contentType = "application/doc";
     objBSS = new BSS_Repository();
    var currentDate = Convert.ToDateTime(DateTime.Now).ToString("ddMMyyyyhhmmss");
    object temporaryFileName = Server.MapPath(_tempPathOnServer) + "GloablDashboard" + "-" + currentDate + ".doc";
   string tempPathOnClient = _tempPathOnClient + "GloablDashboard" + "-" + currentDate + ".doc";
    MSWord.Document document = null;
    try
    {
          // processing for word document
          object missing = Missing.Value;
           MSWord.Application wordApp = new MSWord.Application();
           string templateFile = Server.MapPath(_globalDashboardTemplateFilePath);
            // copy from template file to temporary file
            System.IO.File.Copy(templateFile, (string)temporaryFileName, true);
             if (System.IO.File.Exists(temporaryFileName.ToString()))
             {
                 object readOnly = false;
                  object isVisible = false;
                  document = wordApp.Documents.Open(ref temporaryFileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing);
                  document.Activate();
                   ////  Call FindAndReplace()function for each change
                   this.FindAndReplace(document, "<bsc>", objGlobalDashboard.bscCount);
                   this.FindAndReplace(document, "<bts>", objGlobalDashboard.btsCount);
                   this.FindAndReplace(document, "<nw>", objGlobalDashboard.networkAvailability);
                    ////  save temp.doc after modified
                    document.Save();
               }
                 return Json(new { path = tempPathOnClient }, JsonRequestBehavior.AllowGet);   
                }
                catch
                {
                    ModelState.AddModelError(string.Empty, "File does not exist !!!");
                }
                finally
                {
                    if (document != null)
                    {
                        ((Microsoft.Office.Interop.Word._Document)document).Close(true, Type.Missing, Type.Missing);
                    }
                }
          return Json(new { path = tempPathOnClient }, JsonRequestBehavior.AllowGet);   
       }

PPT/Word文件未从IIS服务器下载

我要做一个大胆的假设:问题不在于你无法下载文件。问题是你的单词automation没有在服务器上运行。我已经完成了服务器端的单词自动化,您的实现——说得轻一点——是乐观的。

当您在本地工作站上运行应用程序时,它将使用您的用户权限运行。在服务器上,它以非常受限的权限运行。例如,Web用户帐户没有DCOM权限。我在这里简要介绍了在配置方面应该做什么:在c#asp.net 中编辑word文档

现在,您的实现很可能会在服务器上运行NullReferenceException。如果它没有首先遇到与互操作相关的异常。它很可能也受到内存泄漏的影响。我强烈建议您在执行其他操作之前先在应用程序中实现一些日志记录。有了这个,你就知道实际的问题是什么了

此外,除非您绝对必须使用,否则您根本不应该使用服务器端单词自动化。您可能需要检查OpenXMLSDK是否也满足您的要求。如果必须使用它,则必须在服务器上运行负载测试,并连接内存探查器以发现内存泄漏。