“应用程序尝试执行安全策略不允许的操作".在共享的虚拟主机服务器上 [英] "The application attempted to perform an operation not allowed by the security policy" on shared webhosting server

查看:217
本文介绍了“应用程序尝试执行安全策略不允许的操作".在共享的虚拟主机服务器上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在ASP.Net 4.0框架中创建了一个Web应用程序,并使用LinqtoSQL进行数据库交互.我已经建立了代码并上传到共享的Web托管服务器上.它的主页运行良好,而所有页面内容都不会与数据库进行交互的所有页面都可以正常运行.但是哪些页面与数据库交互,这些页面给我错误:

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??

所有代码都可以在我们的本地IIS服务器和测试专用服务器上正常工作,但是我们的客户购买了共享服务器,并希望在共享服务器上运行.

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.

推荐答案

注意:在共享托管环境中,这些设置可能已锁定,您必须与您的主机联系.

将LINQ与ASP.NET一起使用

要在以中等信任度运行的Web应用程序中使用LINQ,必须在为中等信任度定义的策略文件中包括两个元素.默认情况下,web_mediumtrust.config文件是用于中等信任的策略文件,并且这些元素已安装在文件中.

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.

在SecurityClasses元素中,LINQ需要具有以下属性的SecurityClass元素:

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"/>

在将Name属性设置为"ASP.Net"的PermissionSet元素中,LINQ需要具有以下属性的IPermission元素:

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"
/>

这篇关于“应用程序尝试执行安全策略不允许的操作".在共享的虚拟主机服务器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆