“应用程序尝试在共享的虚拟主机服务器上执行安全策略不允许的操作”

时间:2011-11-23 12:55:06

标签: asp.net linq-to-sql hosting web-hosting shared-hosting

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

    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

如何在我们的共享服务器上解决此错误?

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

1 个答案:

答案 0 :(得分:1)

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

Using LINQ with ASP.NET

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

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

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

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

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