1
我有一個簡單的網站,它使用C#和Linq to SQL讀取對數據庫的寫入。一切工作正常,在我的本地盒子,但現在,我已經安裝在我的主機環境,我正在嘗試寫入數據庫時,「安全異常」,閱讀是好的。我已經聯繫了託管公司,他們說他們已經在服務器端配置了他們所能做的一切。這是LINQ查詢的例子,並且拋出Linq to SQL - 安全異常
LINQ查詢除外:
public void LogLoginAttempt(string Username, string Password, bool isValidated)
{
try
{
Data.ProfileLoginLog pll = new Library.Data.ProfileLoginLog();
pll.Username = Username;
pll.Password = Password;
pll.isValidated = isValidated;
pll.CreateDate = DateTime.Now;
dc.ProfileLoginLogs.InsertOnSubmit(pll);
dc.SubmitChanges();
}
catch (Exception ex)
{
ErrorLog e = new ErrorLog();
e.LogFatalError(ex);
}
}
例外:
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.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SecurityException: Request for the permission of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Assembly asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed) +150
System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Object assemblyOrString, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed) +100
System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandle rmh, Object assemblyOrString, SecurityAction action, Boolean throwException) +284
System.Security.PermissionSetTriple.CheckSetDemand(PermissionSet demandSet, PermissionSet& alteredDemandset, RuntimeMethodHandle rmh) +69
System.Security.PermissionListSet.CheckSetDemand(PermissionSet pset, RuntimeMethodHandle rmh) +150
System.Security.PermissionListSet.DemandFlagsOrGrantSet(Int32 flags, PermissionSet grantSet) +30
System.Threading.CompressedStack.DemandFlagsOrGrantSet(Int32 flags, PermissionSet grantSet) +40
System.Security.CodeAccessSecurityEngine.ReflectionTargetDemandHelper(Int32 permission, PermissionSet targetGrant, CompressedStack securityContext) +123
System.Security.CodeAccessSecurityEngine.ReflectionTargetDemandHelper(Int32 permission, PermissionSet targetGrant, Resolver accessContext) +41
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3082; ASP.NET Version:2.0.50727.3082
是的,但你如何解決它? – Kieran 2009-12-02 03:45:20
只有兩種方法可以解決此問題:或者將方法更改爲不使用反射或爲您的過程授予使用反射所需的安全許可。我在原始答案中提供的鏈接與其他資源有足夠的鏈接,詳細說明如何獲得所需的安全許可,我將其留給您遵循。 – 2009-12-02 09:57:49