小编Arr*_*ist的帖子

ClosedXML SecurityException:不允许请求的注册表访问

我使用ClosedXML导出Excel文件,我似乎无法导出Excel文件.每次我点击按钮导出Excel文件(XLSX)我都会收到一个错误.见下文...

    using (XLWorkbook wb = new XLWorkbook())
    {
        wb.Worksheets.Add(dsInput);
        Response.Clear();
        Response.Buffer = true;
        Response.Charset = "";
        Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
        Response.AddHeader("content-disposition", "attachment;filename=" + sFileName + ".xlsx");
        using (MemoryStream MyMemoryStream = new MemoryStream())
        {

            wb.SaveAs(MyMemoryStream, false);

            MyMemoryStream.WriteTo(Response.OutputStream);
            Response.Flush();
            Response.End();
        }
    }
Run Code Online (Sandbox Code Playgroud)

我收到此错误:SecurityException:不允许请求的注册表访问.

Exception thrown: 'System.TypeInitializationException' in WindowsBase.dll
System.TypeInitializationException: The type initializer for 
'MS.Utility.EventTrace' threw an exception. ---> 
System.Security.SecurityException: Requested registry access is not allowed.
at System.ThrowHelper.ThrowSecurityException(ExceptionResource resource)
at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)
at Microsoft.Win32.RegistryKey.OpenSubKey(String name)
at Microsoft.Win32.Registry.GetValue(String keyName, String valueName, 
Object defaultValue) …
Run Code Online (Sandbox Code Playgroud)

c# asp.net closedxml

1
推荐指数
1
解决办法
2542
查看次数

标签 统计

asp.net ×1

c# ×1

closedxml ×1