1
Vote

EPPlus IIS Application Pool Identity: NetworkService

description

** Security Issue **

When the IIS Application Pool Identity is set to NetworkService, EPPlus 4.1 throws System.IO.IsolatedStorageException: Unable to create mutex. (Exception from HRESULT: 0x80131464).

Unfortunately, running EPPlus under the Application Pool Identity of LocalSystem is not acceptable in a production environment because these days it is a bad security practice.

Please make this a priority. The following throws the error.
byte[] file = null;
FileStream fs = null;
MemoryStream ms = null;
ExcelPackage pck = null;
ExcelWorksheet ws = null;

//Records is a System.Data.DataTable filled with data.

try
{
    using (ms = new MemoryStream())
    {
        using (fs = new FileStream("<your_file_path>", FileMode.Open, FileAccess.Read))
        {
            using (pck = new ExcelPackage(ms, fs))
            {
                ws = pck.Workbook.Worksheets[1];

                for (int r = 0; r < Records.Rows.Count; r++)
                {
                    for (int c = 0; c < Records.Columns.Count; c++)
                    {
                        string v = Convert.ToString(Records.Rows[r][c]);

                        ws.Cells[(r + 2), (c + 1)].Value = v;
                    }
                }

                file = pck.GetAsByteArray();
            }
        }
    }                        
}
catch (Exception ex)
{
    throw GetAllErrorMessages(ex);
}
finally
{
    ms = null;
    fs = null;
    pck = null;
    ws = null;
}

comments