0

1つのweb.configファイルに2つのロケーション要素があり、コードビハインドの認証を変更したいと思います。

web.configの場所のセクションは次のようになります。

<configuration>
  <location path="~">
    <system.web>
      <compilation debug="false" targetFramework="4.0"/>
      <authorization>
        <allow roles=""/>
        <deny users="*"/>
      </authorization>
    </system.web>
  </location>

  <location path="~/SubPage">
    <system.web>
      <compilation debug="false" targetFramework="4.0"/>
      <authorization>
        <allow roles=""/>
        <deny users="*"/>
      </authorization>
    </system.web>
  </location>
</configuration>

背後にあるコードから、ロケーション要素を調べてから、その特定のロケーション要素に変更を加えたいと思います。たとえば、c#の背後にあるコードは次のようになります。

Configuration myConfig = WebConfigurationManager.OpenWebConfiguration("~");
ConfigurationLocationCollection locations = myConfig.Locations;
foreach (ConfigurationLocation location in locations)
{   
   if (location.Path = "~")
   {
     //define & clear the authorization section of the particular location element.
     //create and apply rule for allow in that authorization section.
     //create and apply rule for deny  in that authorization section.
     //save the change

   }

   if (location.Path = "~/SubPage")
   {
     //define & clear the authorization section of the particular location element.
     //create and apply rule for allow in that authorization section.
     //create and apply rule for deny  in that authorization section.
     //save the change

   }

}

ここでいくつかの異なることを試しましたが、これまで実際に機能するソリューションは1つではありません...ルートディレクトリ(〜)のweb.configへの変更を統合する必要があります(変更を反映する必要があります)このファイルでは、サブページの他のファイルではありません)。空白を埋めるために推奨される実用的な解決策はありますか?目的は、管理者ユーザーが管理者ユーザーインターフェイスを変更して、内部ネットワーク上のどのユーザーまたはWindowsグループが2つの場所を表示できるかを決定できるようにすることです。そのため、許可されている役割をコードビハインドから変更したいと思います。ありがとう。

4

1 に答える 1

0

何度か試行した後、同じファイルにすべての変更を加えることをやめ、代わりに各location.Pathで新しい構成マネージャーインスタンスを開くだけでした。

次に、WebConfigurationManager.OpenWebConfiguration(location.Path)を使用して、各場所の個々のweb.configにルールを適用しました。すべての権限を1か所に集中させることはできませんでしたが、少なくともそれは機能していました。

于 2012-12-04T06:49:51.317 に答える