10

3つのASP.netMVCWebアプリケーションを作成しましたが、すべてISPとの共有ホスティングサーバーに展開されています。

3つのアプリケーションはすべて、構成と設定が非常に似ています。1番目のアプリケーションは、2番目および3番目とは異なるサーバーにデプロイされます。最初のアプリケーションではエラーは発生しません。

2番目と3番目のアプリケーションは、次のSecurityExceptionを いくらか吐き出します:ランダムに:

代替テキスト

リンク

例外テキスト:

 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 for the permission of type 'System.Configuration.ConfigurationPermission, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' failed.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[SecurityException: Request for the permission of type 'System.Configuration.ConfigurationPermission, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' failed.]
   System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
   System.Security.CodeAccessPermission.Demand() +58
   System.Configuration.BaseConfigurationRecord.CheckPermissionAllowed(String configKey, Boolean requirePermission, Boolean isTrustedWithoutAptca) +99


Version Information: Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.3082 

web.configをデプロイまたは編集した後、最初にページにアクセスしたときに上記のエラーが発生します。ただし、後続のページのリロードでは取得できません。2つのWebサイトは、その日の残りの時間は再び正常になりますが、翌朝、同じエラーが再び発生します。

web.configを編集した後、エラーが一貫して表示されます。これは、再コンパイルを強制していると想定していますか?

助けてください。何が問題なのかわかりません。IISのセキュリティ設定に関連しているようです。エラーが発生しない最初のWebアプリが完全に異なるサーバー上にあることを除いて、3つのWebアプリはすべて非常によく似た方法でセットアップおよびデプロイされます。

4

1 に答える 1

20

したがって、上記の SecurityException の理由は 3 つあることがわかります

  • 私のISPは、新しいサーバーでは中程度の信頼モードで実行し、古いサーバーでは完全な信頼モードで実行するようにASP.netを構成しています。私の Web アプリケーションはこれら 2 つのサーバーに分割されています。そのため、アプリケーションがまったく同じように構成されていても、アプリケーション間で異なる動作が得られます。

  • エラー ログに log4net を使用しています。Global.asaxファイルには次の内容があります。

    protected void Application_Start()
    {
        RegisterRoutes(RouteTable.Routes);
        log4net.Config.XmlConfigurator.Configure();
        log.Debug("Logging Initialized.");
    }
    

    この行 -log4net.Config.XmlConfigurator.Configure();上記の例外をスローしているものです。アプリケーションが開始されたとき、またはweb.configが変更された場合は再起動されたときに 1 回だけ発生します。そのため、問題の原因がどこにあるのかわかりませんでした。

  • web.configの log4net configSection にrequirePermission="false"を追加する必要がありました。

    <section name="log4net" requirePermission="false" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
    

中程度の信頼モードで開発していたら、これらの問題を拾っていたでしょう。my web.config に以下を追加することで、アプリを強制的に中信頼モードで実行できます。

  <system.web>
     <trust level="Medium"/>
  </system.web>

アプリを中程度の信頼モードで実行することを強制することで、dev でソースの例外を正確に検出し、そこから何が問題なのかを突き止めました..

于 2010-02-09T13:10:48.180 に答える