ASP.NET Word导出服务器权限配置[windows 2003]

System Requirements

  1. Microsoft Windows Server 2003 with Service Pack 1
  2. MS Word 2003
  3. .Net 2.0

Create a web application. Right click on reference and click on add reference. Select Com tab. Double click on Microsoft Word 11.0 Object Library.

ASP.NET Word导出服务器权限配置[windows 2003]_第1张图片

Add following code to create a word file at a folder in root directory at server it is Word folder in my case.

Object missing = System.Reflection.Missing.Value;

string file = "myfile";

Object filename = Server.MapPath("Word/") + file;            

object readOnly = false;

object isVisible = true;

Microsoft.Office.Interop.Word.Application oWordApp;

try

{

// initializing Word Application

oWordApp= new Microsoft.Office.Interop.Word.Application();

// initializing Word Document  

Microsoft.Office.Interop.Word.Document oWordDoc = oWordApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);

           

try

{

  oWordDoc.Activate();

    oWordApp.Selection.TypeText("This is the text");

    oWordApp.Selection.TypeParagraph();

    // Saving Word file

    oWordDoc.SaveAs(ref filename, 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, ref missing);

    }

    catch (Exception ex)

    {

       Response.Write(ex.Message);

    }

    finally

    {

       oWordApp.Application.Quit(ref missing, ref missing, ref missing);

       // Oppening Word file

       Response.Redirect("~/Word/"+file,true);

    }

}

catch (Exception Wex)

{
    Response.Write(Wex.Message);

}

Now set the Security Permission to the Folder and Com Server

  1. Right click on Word Folder select Properties.
  2. Go to Security tab and assign the following permissions to the users listed below:
    Security Account Permissions
    ASP.NET Machine Account Modify, Read, Write
    IIS_WPG Modify, Read, Write
    Internet Guest Account (IUSR_) * Read, Write
                            
    * These all the account created when IIS installed on the machine.Basicaly IUSR_ is used for anonymous user to access the your website by default. But we can change this user to some other user.So please make sure that Internet Guest Account is the same security account that is used for Basic Authentication for anonymous access for this application. If not then give same permission to that user as IUSR_)

    Note: If any of the above given security accounts are not already present in the user list then please add the user by following the steps given below:
    1. Click on Add

      ASP.NET Word导出服务器权限配置[windows 2003]_第2张图片
    2. Click on Advanced -> Find Now
    3. Select the Particular user
    4. Click on ok

      ASP.NET Word导出服务器权限配置[windows 2003]_第3张图片
  3. DCOM Config changes

    • Go to Run and type coming and click OK.
    • Go to Component Services/Computers/My Computer/DCOM Config
    • Right click on Microsoft Word Application and go to Properties
    • Go to Security Tab
    • Click on Customize and Edit for each section and give Allow permission for each section to following users
      1. 1. ASP.NET Machine Account
      2. 2. IIS_WPG,
      3. 3. Internet Guest Account(IUSR_) *

       

      * Please make sure that Internet Guest Account is the same security account that is used for Basic Authentication for anonymous access for this application. If not then give same permission to that user as IUSR_

      Note: If any of the above mentioned user is not present in user list then please add that user as mentioned in step10 above.

      ASP.NET Word导出服务器权限配置[windows 2003]_第4张图片

    • Go to the Identity tab. Click on This User and assign a user having administrative privileges on the machine.

      ASP.NET Word导出服务器权限配置[windows 2003]_第5张图片

      Note: The Administrative user should have invoked MS Word at least once by logging on to the machine or a complete installation of MS Word 2003 should have been performed. No part of the installation should be remaining.


      原文来自:http://hi.baidu.com/upjoyce/blog/item/9c7233385290c82db9998f40.html


你可能感兴趣的:(asp.net,windows,服务器,security,user,authentication,测试)