中等信任级别的ASP MVC安全异常

时间:2011-10-27 16:23:46

标签: asp.net asp.net-mvc-3

这行代码:

var user = users.SingleOrDefault(u => u.EmailAddress == form.EmailAddress);

其中users是

的集合
public class User
{
    [Key, Required]
    public string EmailAddress { get; set; }

    public string PasswordHash { get; set; }

    public string PasswordSalt { get; protected set; }
}

在中等信任级别时产生异常。

有没有办法让它在这个信任级别工作?

我尝试使用密钥对程序集进行签名,但问题仍然存在。

我正在使用Entity Framework和ASP.NET 4.0。

我无法更改信任级别(代码在完全信任下工作正常)。

这是例外Stack:

SecurityException: Richiesta di autorizzazione di tipo 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=4.0.0.0,    Culture=neutral, PublicKeyToken=b77a5c561934e089' non soddisfatta.]
System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark) +31
System.Security.CodeAccessPermission.Demand() +46
System.Data.Common.Internal.Materialization.Translator.DemandMemberAccess() +50
System.Data.Common.Internal.Materialization.Shaper`1..ctor(DbDataReader reader, ObjectContext context, MetadataWorkspace workspace, MergeOption mergeOption, Int32 stateCount, CoordinatorFactory`1 rootCoordinatorFactory, Action checkPermissions, Boolean readerOwned) +165
System.Data.Common.Internal.Materialization.ShaperFactory`1.Create(DbDataReader reader, ObjectContext context, MetadataWorkspace workspace, MergeOption mergeOption, Boolean readerOwned) +93
System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute(ObjectContext context, ObjectParameterCollection parameterValues) +736
System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) +149
 System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() +44
System.Linq.Enumerable.SingleOrDefault(IEnumerable`1 source) +184
System.Data.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__2(IEnumerable`1 sequence) +41
System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle(IEnumerable`1 query, Expression queryRoot) +59
System.Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute(Expression expression) +150
System.Data.Entity.Internal.Linq.DbQueryProvider.Execute(Expression expression) +102
System.Linq.Queryable.SingleOrDefault(IQueryable`1 source, Expression`1 predicate) +300

1 个答案:

答案 0 :(得分:0)

用户类是什么?是EF还是你自己?如果是你的,请添加AllowPartiallyTrustedCallersAttribute