如何在新的VS2013 Asp.net模板中禁用System.Security.Permissions.ReflectionPermission用法,以便它可以在共享主机上运行

gre*_*eay 14 deployment reflection asp.net-4.5 owin visual-studio-2013

我从默认的MVC模板创建了一个全新的Visual Studio 2013 ASp.net MVC应用程序.但是我收到错误消息请求类型'System.Security.Permissions.ReflectionPermission的权限失败.

是否可以关闭此反射权限,以便网站仍然有效?

这是我的web.config

<?xml version="1.0" encoding="utf-8"?>
    <!--
    For more information on how to configure your ASP.NET application, please visit
    http://go.microsoft.com/fwlink/?LinkId=301880
    -->
    <configuration>
    <configSections>

      <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    </configSections>
    <connectionStrings>
      <add name="MyDb" connectionString="Data Source=x.x.com;Initial Catalog=x;User Id=x;Password=x;" providerName="System.Data.SqlClient" />
    </connectionStrings>
    <appSettings>
      <add key="webpages:Version" value="3.0.0.0" />
      <add key="webpages:Enabled" value="false" />
      <add key="ClientValidationEnabled" value="true" />
      <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    </appSettings>
    <system.web>
    <trust level="Full" />
      <customErrors mode="Off"/>
      <authentication mode="None" />
      <compilation targetFramework="4.5" />
      <httpRuntime targetFramework="4.5" />
    </system.web>
    <system.webServer>
      <modules>
        <remove name="FormsAuthenticationModule" />
      </modules>
    </system.webServer>
    <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
          <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
          <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
          <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
          <bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
          <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
          <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
          <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
          <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
        </dependentAssembly>
        <dependentAssembly>
          <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
          <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
        </dependentAssembly>
      </assemblyBinding>
    </runtime>
    <entityFramework>
      <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
        <parameters>
          <parameter value="v11.0" />
        </parameters>
      </defaultConnectionFactory>
      <providers>
        <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      </providers>
    </entityFramework>
    </configuration>
Run Code Online (Sandbox Code Playgroud)

异常详细信息:System.Security.SecurityException:请求类型'System.Security.Permissions.ReflectionPermission,mscorlib,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'的权限失败.

[SecurityException:请求类型>'System.Security.Permissions.ReflectionPermission,mscorlib,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'的权限失败.] System.Delegate.DelegateConstruct(Object target,IntPtr slot) +0 Owin.Loader.DefaultLoader..ctor(Func 3 next, Func2激活器,IEnumerable1 referencedAssemblies) +69 Microsoft.Owin.Host.SystemWeb.OwinBuilder.GetAppStartup() +65 Microsoft.Owin.Host.SystemWeb.OwinHttpModule.InitializeBlueprint() +28 System.Threading.LazyInitializer.EnsureInitializedCore(T& target, Boolean& initialized, Object& syncLock, Func1 valueFactory)+115 Microsoft.Owin.Host.SystemWeb.OwinHttpModule.Init(HttpApplication context)+106 System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext,HttpContext context,MethodInfo [] handlers)+418 System.Web.HttpApplication.InitSpecial (HttpApplicationState状态,MethodInfo []处理程序,IntPtr appContext,HttpContext上下文)+172 System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext,HttpContext context)+336 System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext)+296

我试着补充一下

<trust level="Full" />
Run Code Online (Sandbox Code Playgroud)

到我的Web.Config system.Web部分但是没有工作,因为我得到了

此配置部分不能在此路径中使用.当站点管理员使用继承的配置文件锁定对此节的访问权限时,会发生这种情况.

它是1and1.com的共享主机,他们不会给我完全的信任.

小智 40

http://www.codeproject.com/Questions/586223/SecurityplusExceptionpluscomingplusinplusaplusrunn

解决方案4 System.Security.SecurityException:请求类型'System.Net.SocketPermission,System,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'的权限失败

以下解决上述错误

<system.web>
    <customErrors mode="Off"/>
    <trust level="Full" />
</system.web>
Run Code Online (Sandbox Code Playgroud)

适用于我的教父托管

  • 在godaddy也为我工作. (3认同)

gre*_*eay 11

我直接询问了asp.net团队,这是他们的回应

我们正式宣布部分信任不再是去年申请隔离的信任边界(http://support.microsoft.com/kb/2698981),因此我们对共享托管服务提供商的建议是不再使用它.展望未来,我们不会支持部分信任我们为此开发的新框架功能.

我知道很多人使用共享主机,因为主机提供商不会完全信任他们的共享主机产品我猜测微软做出了这个决定,因此他们可以在Azure上获得更多客户.

让我们的小型开发人员在共享主机上出售困境.要么去更昂贵的托管或跳到天蓝色.