Issue with Excel in IIS - asp.net

I create excel file with chart and it's working on my local machine with VS inbuilt iis. But when I deployed it on hosting server it's not working. My environment is :
-Win2K8
-IIS 7.0
-MS Office profession
-PIA (2010 tried)
Very first time, I was getting error :
*Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE))*
After some configuration like Dconfig allowing access for Networking service and created desktop folder with full write permission to everyone but I din't got succeeded. Even now I am not getting any error but file is not opening (Excel and PPT). I check our custom application log and system log.
Please guide me why this happening?

Use Office Open XML to create your files instead of automation. There are several libraries out there that will help you build Excel files. I personally use EPPlus and think it's pretty decent.

Related

How to deploy an app using external libraries In IIS

This is my first time using IIS so I don't know much about how it works.
I developed an ASP.net c# web form app, in order to deploy it on a server using IIS. I had Visual Studio installed on the windows server, to make sure the app works fine, no problems up to this point.
When I publish the app from visual studio, and put the file system generated inside inetpub/wwwroot... the pages load fine but just when a I try feature of the app that needs an external library, an exception is raised exactly in the line where the first external library's object instaciated within the code (Information givven by the log).
I'm suspecting that once deployed on IIS app has no reference for the libraries or doesn't have the rights to access them since I haven't touched anything inside IIS besides adding the file system to the depault app pool. But how can I adress this issue?
Here are the two errors traces I got from my log :
Retrieving the COM class factory for component with CLSID {ED0EC116-16B8-44CC-A68A-41BF6E15EB3F} failed due to the following error : 80070154 Class not registred (Exception HRESULT : 0x80040154 (REGDB_E_CLASSNOTREG)).
Or Other Times:
Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error : 80070005 Access Denied. (Exception HRESULT : 0x80070005 (E_ACCESSDENIED)).
Thanks in advance.
The application is run on IIS base on the pool that you have assign it to it. This pool is run under a specific account.
So add this account to the DCOM Config to been able to access it.
First step is to find your pool user as.
Then add permissions for that user on your DCOM Applications so the pool can read them and run them.
To find the DCOM Config, go to
Control Panel | Administrative Tools | Component Services
Then open
Component Services | Computers | My Computer | DCOM Config
There find your applications that you use, left click to open the menu and select properties... there give permissions to your Pool user

Security Exception with SelectPdf .net

I have unloaded the version free Community Edition from
http://selectpdf.com/html-to-pdf/demo/
Because I wanted to use the example that turned a page html into pdf.
In visual studio I have succeeded in using the file asp.net but when I put it online I receive this error:
Security Exception
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.
Exception Details: System.Security.SecurityException: That assembly does not allow partially trusted callers.
I have loaded the files on three different servers.
Azure, Aruba and Godaddy, but do I always receive the same error, as I can resolve?
http://pdf.cyberkings.fr/html-to-pdf-converter.aspx
http://www.numero-telefono.it/html-to-pdf-converter.aspx
Thanks
Conversion failure. Could not find 'Select.Html.dep'.
Description: An unhandled exception occurred during the execution of the current web request
When installing Select.HtmlToPdf from NuGET, the installation copies the dependancy file Select.Html.dep to the bin. When you build, a copy gets placed in the /bin beside Select.HtmlToPdf.dll.
However, when deploying your application, the dependency file does not get copied automatically.
You need to copy Select.Html.dep manually.
See the SelectPdf Html To Pdf Converter for .NET deployment documentation.

Word Automation with ASP.NET

I have an old application that uses Microsoft Word automation in asp.net and I need to install it on a Windows Server 2012 R2 x64 with Office 2013 Standard x86. I know that Office automation in server technologies like IIS should be avoided but I don't have the green light to rewrite the application at the moment, so I have to take it as-is.
Initially I started the application and it gave this error:
Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
I found some information online that {000209FF-0000-0000-C000-000000000046} is the identifier of generic Word, no specific version.
I went to Component Services -> My Computer -> DCOM Config -> Microsoft Word 97 - 2003 Document (note that there is no node for Microsoft Word or MS Word or Word while there is one for Microsoft Excel) and changed the security to allow the IIS AppPool user "Local Launch", "Local Activation" and "Local Access". This makes the application take some time to respond (more than a minute) and fail with the following error:
Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
At the same time the event viewer System log shows:
The server {000209FF-0000-0000-C000-000000000046} did not register with DCOM within the required timeout.
I searched online and found some information that access rights might not be OK, including system drive paths and registry. I ran Process Monitor and checked what the process is trying to open. I gave the IIS AppPool user full access to the following:
C:\Windows\SysWOW64\config\systemprofile
C:\Windows\Temp
HKU.DEFAULT\Software\Microsoft\Office
HKLM\Software\Wow6432Node\Microsoft\Office
HKLM\Software\Wow6432Node\Microsoft\Shared Tools
When I ran the application again it only showed a few access problems in Process Monitor which seem to be just attempts to read different configurations. The application itself did not show any kind of error any more, it just freezed. I don't have Visual Studio installed on that machine, but I don't see any errors in the application logs, so no exceptions were thrown.
I tried also setting a specific user (local administrator) in the DCOM Identity but there was no change.
Now I restored all permissions and I am back to the 0x80080005 error because it at least gives me some information to try to go with.
I succeeded to reproduce the error in a simple application with this code:
try
{
l1.Text = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
var application = new Microsoft.Office.Interop.Word.Application();
l2.Text = "OK";
}
catch (Exception ex)
{
this.Label2.Text = ex.ToString().Replace("\r\n", "<br/>");
}
It fails also on Windows 8 x64 with Office 2013 Pro x64, with exactly the same error.
If I impersonate the current user to be an administrator, then it works. However even adding IIS APPPOOL\DefaultAppPool to the administrators group, it still fails.
Any ideas on the next steps?
So this is what worked at the end:
Create an admin user and set Word to run with it in the DCOM settings
In the settings give activation, launch and access permissions to the AppPool user as well as IIS_IURS and IUSR. Note that if you don't give the rights for the others, only to the AppPool user, Windows will still report that the AppPool user does not have sufficient privileges which is totally misleading
I also figured out what the problem with the freezing Word was: creating the new file was causing Word to open in the special mode where it tells you that the file might be dangerous. Of course using COM you don't see the problem but it would then not be able to continue until you allow it. This is a new behavior in Word 2013 and that's why I didn't have it before.
I had the exact same error with legacy code using Office Interop on Windows Server 2016 with Office 2013 and it drove me mad. So first I want to join those who already mentioned that the best practice would be to not use it and rewrite your code to DocX or similar if you have any chance. It just has too many traps that eat up time.
I followed all hints of Vladimirs post but still got the error. After all it was the doc file templates of the project Office failed to open in Interop mode (but which opened without any problem in the RD session on the server). They were created in an older Office Version. I opened/saved the templates in Word once and everything worked fine.

Upgrading to 2K8 Server, An error occurred loading a configuration file: Failed to start monitoring changes to '\\networkshare'

I moved my site off of a 2k3 server over to a 2k8 server. The site has a virtual directory pointed to a network share which has different credentials than the one used by the site. I set the virtual directory to use the correct credentials and it can browse the share fine through explorer, but when I try to load files (images, etc) through a browser I get the following asp.net error:
Server Error in '/' Application.
Configuration Error Description: An error occurred during the
processing of a configuration file required to service this request.
Please review the specific error details below and modify your
configuration file appropriately.
Parser Error Message: An error occurred loading a configuration file:
Failed to start monitoring changes to '\\networkshare'.
Source Error:
[No relevant source lines]
Source File: \\networkshare\web.config Line: 0
Version Information: Microsoft .NET Framework Version:2.0.50727.5456;
ASP.NET Version:2.0.50727.5456
The network share does not have a web.config.
I tried the solution provided here, but that did not solve the issue and this site isn't using impersonation. Do I need to enable impersonation? This was working correctly on win2k3.
OK, so based on our comments it sounds like this is either a share permissions problem or an NTFS permissions problem (same resolution, different dialog).
In IIS6 you typically had the worker process running as NETWORK SERVICE and that's what you would give permissions to to access shares and files on the network.
In IIS7.5 the application pools now run under an AppPool identity, one specific to the application pool that the website is running under. This link should be helpful: http://learn.iis.net/page.aspx/624/application-pool-identities/
As a quick fix (although I recommend reading up on it) though, you can go into the application pool, go to advanced properties, and set the identity back to NETWORK SERVICE.

Visual Studio Build error after copy solution to new location

I inherited Visual Studio 2010 Web Site solution.The solution is pretty simple (but large), and only contains one project.
BUT when I copy the site to another location on my hard drive and try to build it, I get the following error:
Error 1
An error occurred loading a configuration file: Failed to start monitoring changes to 'C:\Development\SolutionFolder\app_code' because access is denied. C:\Development\SolutionFolder\app_code\web.config
Looks like some impersonation issue. Please check the local user permission on the app_code folder.

Resources