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つの場所を表示できるかを決定できるようにすることです。そのため、許可されている役割をコードビハインドから変更したいと思います。ありがとう。