System.Security.SecurityException:请求类型为“ System.Security.Permissions.FileIOPermission,mscorlib,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089”的权限失败。
在将多个图像压缩为zip时,我得到了以上提示...
我的代码只能在本地运行,而不能实时运行。
我在web.config行下面尝试过。
<trust level="Full" />
但问题没有解决。
Web.Config
<system.web>
<trust level="Full" />
<customErrors mode="Off"/>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true" />
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows" />
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
</system.web>
按钮代码:
protected void DownloadFiles(object sender, EventArgs e)
{
String StrSql = "";
OleDbConnection Cn = new OleDbConnection(System.Configuration.ConfigurationManager.AppSettings["con"].ToString());
StrSql = "select Convert(nvarchar(50),WdPrefix)+''+Convert(nvarchar(50),WdCertNo)+''+Convert(nvarchar(50),WdCertChr) as CertificateNo from WorksheetDetails where WdRefId='" + ClsBackOffice.Decrypt(spnWmId .InnerHtml)+ "'";
OleDbDataAdapter Da = new OleDbDataAdapter(StrSql, Cn);
DataSet Ds = new DataSet();
DataRow R;
Da.Fill(Ds, "DATA");
ZipFile zip = new ZipFile();
zip.AlternateEncodingUsage = ZipOption.AsNecessary;
zip.AddDirectoryByName("Files");
for (Int16 i = 0; i < Ds.Tables["DATA"].Rows.Count; i++)
{
R = Ds.Tables["DATA"].Rows[i];
String mFileName=R["CertificateNo"].ToString();
String filePath = AppDomain.CurrentDomain.BaseDirectory.ToString() + @"TempFiles\" + mFileName + "-Print.jpg";
zip.AddFile(filePath, "Files");
}
Response.Clear();
Response.BufferOutput = false;
string zipName = String.Format("Zip_" + spnJobCardNo.InnerHtml + ".zip");
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "attachment; filename=" + zipName);
zip.Save(Response.OutputStream);
Response.End();
}
此行发生错误:
zip.AddFile(filePath, "Files");