简体   繁体   中英

Moving From ASP.Net 3.5 to 4.0 - System.Security.Permissions.FileIOPermission Exception

I'm sure this can't be too hard; but I'm struggling. The error is

Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

I'm trying to write to a text file on the server. Before, I had to modify the web.config file set the trust level to full. Then it all seemed to work.

I've since updated my site to use ASP.NET 4.0; and now I can't pull it off. I'm really not doing much at all, just reading/writing a file. But now I can't get past the error. From what I've read, it sounds like 'Full' is the default setting in 4.0?

I have a (virtually) empty web.config. I tried adding the trust level to explicitly set it to full but it didn't seem to help.

EDIT

I'm currently using File.AppendAllText to write to the file and File.ReadAllText to read the contents.

And this is IIS7.

If it sounds like this isn't programming related, I can take it up with customer support for my host. But, like I said, if I switch my site back to 3.5 it works great. When I set it to 4.0 - I get this error.

Here is a whitepaper on many of the breaking changes in ASP.NET 4.0 http://www.asp.net/learn/whitepapers/aspnet4/breaking-changes

It looks like the security model had a significant overhaul...but it looks like the short answer for my problem is to add:

   <trust level= "Full" legacyCasModel="true" />

legacyCasModel should give you the old behavior from previous editions of ASP.NET. This worked for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM