Dienstag, 16. Juni 2009

Separieren von web.config Daten

Es gibt manchmal Situationen in welchen man gerne Daten aus der web.config aus der Applikation bearbeiten würde. Jedoch sind durch ASP.NET .config Dateien aus der Applikation nicht zugänglich. Es gibt einen kleinen Workaround, der jedoch eine kleine Sicherheitslücke öffnet. Dessen sollte man sich bewusst sein. Man hat die Möglichkeit Daten aus der web.config auszulagern. Was man dann machen kann, ist die Daten in einem selbsternannten XML File zu speichern und auf dieses aus der Applikation zuzugreifen.
Man kann in der web.config die AppSettings oder ConnectionStrings per configSource auslagern. Man verwendet dann eine test.test Datei, Endung kann man selbst bestimen z.B. test.Firmenname und dort lagert man die Nodes aus. Man kann jetzt per XML zugreifen und Änderungen vornehmen. Vielleicht sollte man vorher noch die Rechte auf dieses File zur Sicherheit ändern.

There are sometimes situations, where you would like to change data in the web.config out of the application. ASP.NET usually blocks .config files to be changes out of the application. There is a little work-around to this situation. But be aware, that this reduces a little bit your application- security.
You can outsource the AppSettings or ConnectionString with configSource. Then you create a new test.test file (you can use any file-type also own one) and paste the nodes in there. You can now access this file with XML and make changes. Maybe you should set different permissions on this file to add some security.

web.config
<appSettings configSource ="test.test" />

test.test File
<appSettings>
<!-- your key/values -->
</appSettings>

Keine Kommentare:

Kommentar veröffentlichen