【问题标题】:The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons)此应用程序的当前自定义错误设置阻止远程查看应用程序错误的详细信息(出于安全原因)
【发布时间】:2015-09-24 12:59:02
【问题描述】:

我使用 VS2013 的 FTP 发布选项在 plesk 中托管了我的 MVC 网站,一切正常,我的意思是所有需要的文件都正确复制到了 httpdocs 虚拟目录下的目标位置。但是当我访问 URL 时,我现在遇到以下错误:

我已经尝试了许多链接中提到的所有可能的解决方案,但没有合适的解决方案!这让我很困惑!

我曾尝试在 this 中应用解决方案,并且还检查了 this question,但它们都没有用。我的web.config 文件如下:

<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=sometoken" requirePermission="false" />
  </configSections>
  <appSettings>
    <!--<add key="MaintenanceMode" value="false" />-->
    <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="SessionTimeoutRedirect" value="true" />
    <add key="isAjaxHandled" value="false" />
  </appSettings>
  <system.web>
    <customErrors mode="Off" />
    <trust level="Full"/>
    <compilation targetFramework="4.0" defaultLanguage="c#"/>
    <httpRuntime executionTimeout="1048576" maxRequestLength="100000" />
    <globalization culture="en-IN" uiCulture="en-IN" />
    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login" defaultUrl="~/Admin/Index" timeout="2880" protection="Encryption" slidingExpiration="true" cookieless="AutoDetect" />
    </authentication>
    <pages controlRenderingCompatibilityVersion="4.0" />
  </system.web>
  <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>
  <connectionStrings>
    <add name="MCBConnectionString" connectionString="metadata=res://*/Models.EntityDataModel.MCBEntityModel.csdl|res://*/Models.EntityDataModel.MCBEntityModel.ssdl|res://*/Models.EntityDataModel.MCBEntityModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=somesource;Network Library=;Packet Size=4096;Integrated Security=no;User ID=uid;Password=pwd;Encrypt=yes;TrustServerCertificate=True; integrated security=no;connect timeout=120;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="1073741824" />
      </requestFiltering>
    </security>
  </system.webServer>
</configuration>

以下是 Plesk 管理面板中的文件结构

还有一点需要注意:如果我从web.config 中删除&lt;trust level="Full"/&gt; 标签,我不会收到任何错误,但也不会显示。将显示一个空白页面

对此我真的很困惑!除了现在访问这个论坛,我别无选择!有没有遇到这个问题的专家,或者我需要在web.config 上进行更多配置?

【问题讨论】:

    标签: asp.net-mvc visual-studio-2013 asp.net-mvc-5 web-hosting plesk


    【解决方案1】:

    放置以下代码

    &lt;compilation debug="true" targetFramework="4.0"&gt;

    而不是

    <compilation targetFramework="4.0" defaultLanguage="c#"/>
    

    希望能成功

    This Link 实际上可以帮助您识别服务器中未显示的任何类型的问题,因此我 [OP] 能够通过识别问题来解决我的问题。

    以下是链接包含的内容:

    在使用 ASP.NET 时,您可能会遇到以下错误:“安全 异常”“异常详细信息:System.Security.SecurityException: 安全错误。”

    这意味着一个类在运行时被链接到一个受限的 班级。默认情况下,ASP.NET 错误消息针对 仅编译时和运行时错误。所以真正的错误来源是 不显示链接错误。例如,如果出现这些错误,如果 您尝试访问注册表变量或系统变量等。 有时您可以通过放置以下内容来获取详细的错误消息 global.asax 文件中的代码。

    <%@ Application %> 
    
    <script runat="server" language="c#">
    protected void Application_Error(Object sender, EventArgs e){
    Exception ex = Server.GetLastError();
    Server.ClearError();
    
    Response.Write("<pre>");
    Response.Write(Environment.NewLine);
    Response.Write("Caught Exception: " + ex.ToString() + Environment.NewLine);
    
    if (ex.InnerException != null){
    Response.Write(Environment.NewLine);
    Response.Write("Inner Exception: " + ex.InnerException.ToString() + Environment.NewLine);
    Response.Write(Environment.NewLine);
    }
    
    System.Security.SecurityException ex_security = ex as System.Security.SecurityException;
    
    if (ex_security != null){
    Response.Write(Environment.NewLine);
    Response.Write("Security Exception Details:");
    Response.Write(Environment.NewLine);
    Response.Write("===========================");
    Response.Write(Environment.NewLine);
    Response.Write("PermissionState: " + ex_security.PermissionState + Environment.NewLine);
    Response.Write("PermissionType: " + ex_security.PermissionType + Environment.NewLine);
    Response.Write("RefusedSet: " + ex_security.RefusedSet + Environment.NewLine);
    }
    
    Response.Write("</pre>");
    }
    </script>
    

    【讨论】:

    • 我也尝试过这种可能性,伙计! :( 我会得到同样的错误!!
    • 之前你需要删除 trust level=full
    • 在我的情况下,它的 MVC 和我将拥有 .cshtml 文件而不是 .aspx ,这将是内部视图!知道如何为 MVC 提供默认文档吗?
    • routes.MapRoute( "Default", // 路由名称 "", // 带参数的 URL new { controller = "Home", action = "Index"} // 参数默认值 );跨度>
    • 我在三层 asp.net 中也遇到了这个错误,但是在添加这个之后,链接中显示的代码我可以在服务器上完美查看以下链接help.1and1.com/hosting-c37630/…
    【解决方案2】:

    如果您使用的是 asp.net mvc5,它需要完全信任,在我写这篇文章的那一刻,plesk(主机 gator)不支持。

    如果是这种情况,您需要降级到 mvc4 或寻找另一个支持完全信任的托管服务提供商

    【讨论】:

    • 你现在写这个?你写什么?我会试试你降级到 MVC4 的建议。
    • “在我写这篇文章的那一刻”是指 plesk hostgator 不支持 asp.net mvc5,但它可能会或将来会支持。
    猜你喜欢
    • 2012-06-02
    • 1970-01-01
    • 1970-01-01
    • 2015-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-18
    相关资源
    最近更新 更多