0

これが可能であるとは思えませんが、当社の Web アプリケーションの 1 つが顧客によって使用され、ライブ/テスト データベースを持っています。現時点では、両方のフォルダーにディレクトリが設定されており、web.config ファイルがライブまたはテストのいずれかを指しているため、更新は両方のフォルダーに移動する必要があります。

1 つのディレクトリだけを使用できますが、IIS で 2 つの Web アプリケーションをそれぞれ異なる web.config ファイルまたは同様のものを使用して使用できるので、1 つの場所だけを更新する必要がありますか?

4

2 に答える 2

0

Depending on your database connection system, you could supply it with a connectionstring based on a usersetting rather than based on the web.config? There has to be some way of deciding which database a user wants to use, this could be something as simple as buttons or dropdown list for selecting, or keep the system with two folders but use an URL route to make them both point to the same files. Then when you instantiate your database connection you can supply the correct connectionstring and you're set.

Edit: After chat the solution has been to put two connectionstrings in web.config, one for the Test database and one for Production. Then add routing to pretend the two folders are still there, with the following basic idea:

routes.Add(new Route("{folder}/{page}", new PageRouteHandler("~/{page}")));

Lastly a function to decide which connectionstring to use based on the folder value in the routing values: Request.RequestContext.RouteData.Values["folder"], and a global refactor to use this dynamic connectionstring rather than a hardcoded one.


For having "multiple" web.configs, you can make a config section specific to a file path, see http://msdn.microsoft.com/en-us/library/b6x6shw7%28v=vs.71%29.aspx However I am not sure wheter this works for connectionstrings.

Example:

<configuration>
   <location path="Logon.aspx">
      <system.web>
         <authorization>
            <allow users="?"/>
         </authorization>
      </system.web>
   </location>
</configuration>
于 2012-10-08T14:55:22.670 に答える
0

できますが、少し異なる方法で物事を維持する必要があります。あなたが私たちに言っていないのは、構成値の分離を使用している唯一の場所はconnectionStringsappSettingsですか? それとも他に違いはありますか?

次に、これらの値を別の構成ファイルからロードする必要があり、既存の構成ファイルによって参照されず、System.Configuration.ConfigurationManagerまたはその名前空間/ユーティリティを使用してロードされません。次のステップは、受信 URL を使用して、設定クラスで使用されているデータを分離し、2 つのデータ ポイントのどちらをロードするかを知ることです。

それ以外の場合、この方法でアプリを作成する場合、これは完全に有効です (他の世界で私たちが慣れ親しんでいることに少し反するだけです)。

于 2012-10-08T14:50:07.617 に答える