【问题标题】:Asp.net MVC5 website hosting on godady: System.Security.SecurityExceptionGodaddy 上的 Asp.net MVC 5 网站托管:System.Security.SecurityException
【发布时间】:2018-10-13 23:10:35
【问题描述】:

我使用带有 .netframework 4.5.2 的 Visual Studio 2015 创建了一个网站。该网站在本地机器上运行良好,但是当我上传了在 Godaddy 中发布网站时。首先我得到错误自定义错误需要关闭。我添加了标签来解决这个问题。

<customErrors mode="Off"/>

然后我收到信任权限错误“System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed” . 我google了一下,发现需要在服务器的web.config和asp.net设置中将信任级别设置为full。 我在 Godaddy 服务器和 web.config 设置中将 CAS 信任级别设置为完全,但仍然无法正常工作。

<trustLevel name="Full" policyFile="internal"/> 

我收到内部服务器错误。 我又试了一次,还是同样的错误。

<securityPolicy>
    <trustLevel name="Full" policyFile="internal"/>
 </securityPolicy>

我不确定需要对 web.config 文件进行哪些更改才能正常工作。请找到我的 web.config

<configuration>
 <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=SAFIRE\SQLEXPRESS;Initial Catalog=Hotel;Integrated Security=True" 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" />
    <add key="MvcMailer.BaseURL" value="" />
</appSettings>
<system.web>    
 <authentication mode="None" />    
 <customErrors mode="Off"/>
 <compilation debug="true" targetFramework="4.5.2" />
    <httpRuntime targetFramework="4.5.2" />
    <trustLevel name="Full" policyFile="internal" />
</system.web>
<system.webServer>
    <modules>
        <remove name="FormsAuthentication" />
    </modules>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
    <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.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="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="0.0.0.0-5.2.3.0" newVersion="5.2.3.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="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
  </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.SqlConnectionFactory, EntityFramework" />
    <providers>
        <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
</entityFramework>
<system.net>
    <mailSettings>
        <smtp from="xxx">
        <network host="smtpout.europe.secureserver.net" port="25" userName="xxx" password="xxx" />
        </smtp>
    </mailSettings>
</system.net>
<system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
    </compilers>
</system.codedom>

我是否缺少 web.config 的某些设置?

【问题讨论】:

    标签: asp.net-mvc web-config


    【解决方案1】:

    你必须清除 system.Codedom 删除该部分并添加&lt;system.codedom/&gt;

    这对我有用

    【讨论】:

      【解决方案2】:

      你应该做几件事来找出问题

      1) 检查连接字符串是否包含“integrated Security=true”,如果为真则表示网站尝试使用windows凭据连接数据库,尽量不要使用windows凭据

      2)如果这不能解决问题,则暂时打开自定义错误,然后浏览网站,它应该会给出一些有意义的错误消息

      【讨论】:

      • 这是评论,不是答案。问题明确后,您可以发布答案。如果问题不明确,请发表评论要求澄清。
      • 我确实将连接字符串更改为Godaddy数据库中的连接字符串并打开了自定义错误。仍然显示相同的错误。 500 内部服务器错误。
      • 我用 更新了 we.config。现在我收到 403 禁止错误。您无权访问此文档。我想这是一个信任级别问题,在将信任级别设置为完整后不确定我哪里出错了。
      • 在您的代码上,您需要尝试为您的文件夹授予完全权限。请测试。
      猜你喜欢
      • 1970-01-01
      • 2010-10-18
      • 2023-03-27
      • 1970-01-01
      • 2018-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-07
      • 2019-04-06
      相关资源
      最近更新 更多