Starting a program which is a part of large package from an ASP.NET web page

1

The project I am working on has a requirement to generate a LaTeX file in an ASP.NET VB web page and run PDFLaTeX program to compile into PDF.

I tried that in a local web server from within Visual Studio and it worked fine. But when I created a virtual host in IIS for the same application directory, PDFLaTeX could no longer be invoked with an Information event being written to the System event log when ASP.NET was compiled in Release mode:

Application popup: pdflatex.exe - Application Error :
The application was unable to start correctly (0xc0000142).
Click OK to close the application.

If the app was compiled in Debug mode, there was an error about not being able to invoke Machine Debug Manager: The application-specific permission settings do not grant Local Activation permission for the COM Server application with CLSID ....

Some answers here suggested moving an exe to be run into the web site's virtual directory. In my particular case this is hardly possible, as I need to invoke PDFLaTeX to compile a .tex file into .pdf. For the obvious reasons I cannot move entire texlive installation into each of the web applications' virtual folders.

The application works fine in a VS local development server and compiles latex file into PDF. DOM\usr is a local admin who has permission to read and write to/from all directories involved. We really don't care about security right now for several good and sufficient reasons and just need to make it work even with hacks, no matter how dirty.

Protected Sub btnPDF_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPDF.Click
    Try
        Dim p As Process = New Process()
        p.StartInfo.UseShellExecute = False
        p.StartInfo.Domain = "DOM"
        p.StartInfo.UserName = "usr"

        Dim ss As SecureString = New SecureString
        For Each c In s.ToCharArray()
            ss.AppendChar(c)
        Next

        p.StartInfo.Password = ss 'Password set elsewhere
        p.StartInfo.FileName = "D:\texlive\2013\bin\win32\pdflatex.exe"
        p.StartInfo.Arguments = "D:\a.tex"
        p.StartInfo.WorkingDirectory = IO.Path.GetDirectoryName(p.StartInfo.Arguments)
        p.StartInfo.RedirectStandardOutput = True
        p.StartInfo.RedirectStandardError = True
        p.Start()
        Dim output As String = p.StandardOutput.ReadToEnd()
        Dim errors As String = p.StandardError.ReadToEnd()
        p.WaitForExit()

        LogEvent(output, EventLogEntryType.Information) ' These 2 events 
        LogEvent(errors, EventLogEntryType.Warning)     ' have empty event text
    Catch ex As Exception
        LogEvent(ex.Message, EventLogEntryType.Error)
    End Try
End Sub

Private Sub LogEvent(ByRef msg As String, ByRef t As EventLogEntryType)
    Dim eventLogPerm As EventLogPermission = New EventLogPermission(EventLogPermissionAccess.Administer, ".")
    eventLogPerm.PermitOnly()

    Dim evLog As EventLog = New EventLog
    evLog.Source = "ASP.NET 2.0.50727.0" ' Quick hack to not have to register new source
    evLog.WriteEntry(msg, t)
End Sub
asp.net
vb.net
pdflatex
asked on Stack Overflow Feb 10, 2014 by ajeh

1 Answer

1

This is likely the issue of permissions of Application Pool identity. Check IIS what account the AppPool (under which your web application is running) uses. Use an account with enough rights to execute the program that you need to run.

answered on Stack Overflow Feb 11, 2014 by Igor

User contributions licensed under CC BY-SA 3.0