“The application attempted to perform an operation not allowed by the security policy” on shared webhosting server

僤鯓⒐⒋嵵緔 提交于 2019-12-13 17:19:16

问题


I have created a web application in ASP.Net 4.0 framework and use LinqtoSQL for database interaction. I have build my code and upload on my shared web hosting server. Its home page working fine and all pages working fine where page content doesn't interact with database. But which pages interact database these pages gives me error :

    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 failed.
    Stack Trace:

   [SecurityException: Request failed.]
   DataContextFactory.GetWebRequestScopedDataContextInternal(Type type, String key, String connectionString) in DataContextFactory.cs:81
   DataContextFactory.GetWebRequestScopedDataContext() in DataContextFactory.cs:42
   members_buyer_mypostedjobs..ctor() in mypostedjobs.aspx.cs:19
   ASP.members_buyer_mypostedjobs_aspx..ctor() in App_Web_soaq30qq.4.cs:0
   __ASP.FastObjectFactory_app_web_soaq30qq.Create_ASP_members_buyer_mypostedjobs_aspx() in App_Web_soaq30qq.9.cs:0
   System.Web.Compilation.BuildResultCompiledType.CreateInstance() +32
   System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp) +109
   System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +31
   System.Web.UI.PageHandlerFactory.GetHandler(HttpContext context, String requestType, String virtualPath, String path) +37
   System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +334
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

How to resolve this error on our shared server??

All code works fine on our local IIS server and our testing dedicated server but our client purchased a shared server and wants to run at shared server.


回答1:


NOTE: In a shared hosting environment these setting are probably locked down, you will have to contact your host.

Using LINQ with ASP.NET

To use LINQ in a Web application that is running under medium trust, you must include two elements in the policy file that is defined for Medium trust. By default, the web_mediumtrust.config file is the policy file for medium trust, and these elements are installed in the file.

Within the SecurityClasses element, LINQ requires a SecurityClass element with the following attributes:

<SecurityClass 
  Name="ReflectionPermission" 
  Description="System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>

Within the PermissionSet element that has the Name attribute set to "ASP.Net", LINQ requires an IPermission element that has the following attributes:

<IPermission
  class="ReflectionPermission"
  version="1"
  Flags="RestrictedMemberAccess"
/>


来源:https://stackoverflow.com/questions/8242531/the-application-attempted-to-perform-an-operation-not-allowed-by-the-security-p

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!