我将 ASP.NET 4.0 与 C# 一起用于 Web 应用程序。有一部分是从 excel 文件导入数据。我已经使用 Microsoft.Jet.OLEDB.4.0 来做到这一点。 过程是——
- 上传文件到App_Data目录
- 将数据检索到列表
- 从 App_Data 中删除上传的文件
它在我的本地主机上运行良好。但是当我在 Godaddy 托管网站时,它无法执行数据提取。
Server Error in '/' Application.
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: Request for the permission of type 'System.Data.OleDb.OleDbPermission, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
Source Error: [No relevant source lines]
Source File: App_Web_importquestion.aspx.2edad644.wy5h2tcw.0.cs
Line: 0Stack Trace:
[and so on.....]
我确定App_Data目录有读写权限,我可以看到它成功上传了文件到App_Data文件夹。
最佳答案
在<System.Web>
你的部分web.config
文件,添加以下内容:
<trust level="Full" />
这应该会提升您的信任度,之后您应该能够正常工作。
关于c# - OLEDB 安全异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24942021/