2017-10-26 15 views
-2

私のアプリケーションはasp.net(4.5)webform C#で動作しています。私のアプリケーションでは、Excelシートを作成する必要があります。このエラーを修正する必要があります

// code to create excel 
xlsWorkbook.SaveAs("C:\\" + filename, XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue); 
xlsWorkbook.Close(true, filename, null); 
xlsApp.Quit(); 
xlsWorksheet = null; 
xlsWorkbook = null; 
xlsApp = null; 
Process.Start(@"c:\"); // Open file after download 

ご覧のとおり、私は生成されたExcelファイルをCドライブに保存しています。私がローカルで走っている間、これは完璧に動作します。しかし、公開後、このエラーは**この問題を解決するための方法

**

Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)). 
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: Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)). 
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 and IIS 7, and the configured application pool identity on IIS 7.5) 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 access to a file, right-click the file in File 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: 
[UnauthorizedAccessException: Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).] 
    System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0 
    System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +119 
    System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +247 
    System.Activator.CreateInstance(Type type, Boolean nonPublic) +83 
    System.Activator.CreateInstance(Type type) +11 
    e2aPortal.homeUserControl.CreateTopic.ExportToExcel() +112 
    e2aPortal.homeUserControl.CreateTopic.btnDownloadExcel_OnClick(Object sender, EventArgs e) +5 
    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9767618 
    System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +204 
    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12 
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15 
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35 
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1738 

を投げていますか?

+0

実動マシンのIISでファイル/フォルダのアクセス許可を確認しましたか?同様の問題で提案されているように 'LocalSystem'を使ってみてください:https://stackoverflow.com/questions/17785063/retrieving-the-com-class-factory-for-component-error-80070005-access-is-de。 –

+0

アプリケーションプールは、サーバー上のすべてにアクセスできないアカウントで実行されます。これは、セキュリティ上の理由や理由からです。ユーザーがこれらのファイルにアクセスできるようにするには、アプリケーションプールアカウントにファイルの場所へのアクセス権を与える必要があります。イントラネットで、ウィンドウ認証を使用している場合は、偽装を使用して、誰がファイルに対して何をしたのかを把握します。 – CodingYoshi

答えて

0

メッセージに許可の問題があります。アプリケーションは、インストールされているマシン上でWindowsユーザーとして実行されます。どのユーザーが実行されているか知っていますか? (1)c:ドライブのルート(または理想的には特定のサブフォルダ)に書き込む権限をそのWindowsユーザーに与える (2)より高い特権を持つ別のユーザーの下でアプリケーションを実行する (3)ファイルを作成する場所を指定するアプリケーション設定ファイルの設定を使用します。 は(4)ユーザーのデフォルトのフォルダ(C:\ Users \ユーザー名)への書き込み、私はこれがcをかけることなく、ファイル名を指定して実行されると思う:ExcelのDLLを使用して、それの前に\

xlsWorkbook.SaveAs(filename, XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue); 
0

ではありませんWebアプリケーションのための良いアイデアです。 DCOM設定を構成し、w3wpにアクセスさせてセキュリティの問題を引き起こす可能性があります。

あなたの要望はダウンロード用のExcelファイルを作成することです。 あなたがNPOI NPOI

を試すことができます。このプロジェクトはhttp://poi.apache.org/でPOI Javaプロジェクトの.NETバージョンです。 POIはxls、doc、pptファイルの読み書きに役立つオープンソースプロジェクトです。それは広い適用を有する。

関連する問題