c# - Set IHttpModule.properties in web.config -


I have created my own HttpModule called 'JsonLogger' to log json requests and responses.

Logging I need a connection string.

To find the connection string, I added one to my web.config and got it from the code.

web.config

& lt; Connection best & gt; & Lt; Add Name = "WebShop Configuration" Connection String = "MichaelString" / & gt; & Lt; / ConnectionStrings & gt; & Lt; System.web & gt; & Lt; HttpModules & gt; & Lt; Add name = "Jasonolgor" type = "ServiceModel Logging .Jesolologer, Service Model" /> & Lt; / HttpModules & gt; & Lt; /system.web> & Lt; System.webServer & gt; & Lt; Module & gt; & Lt; Add name = "Jasonolgor" type = "ServiceModel Logging .Jesolologer, Service Model" /> & Lt; / Module & gt; & Lt; /system.webServer>

http module

  connection string = system. Configuration. Configuration Manager . ConnectionStrings ["WebShopConfiguration"] ConnectionString;  

Everything works fine but IMO is not clear (future developers do not know why that connectionstring is in my web.config).

I would like to fill the connection string where I add httpmodule to my web.config. I tried to do this but it is not working (as I had already thought):

web.config

  & lt; Add name = "JsonLogger" type = "ServiceModel Logging .Jesolologer, Service Model" connection string = "MichaelString" / & gt; Property in the HTTPS module   
  [Configuration property ("connection string", default value = "", ISUAIFE = true, iski = false)] public string connection string {get; Set; }  

After some research, I did not find any way to do this. Anyone knows what I am trying to achieve is possible?

Many thanks, Kejel

I have done this

< P> In my web.config I added a configSection with a type of logging configuration. I get my configuration in Global.asax init () and create a new JsonLogger instance with the correct parameter.

web.config

  & lt; ConfigSections & gt; & Lt; Section name = "logging configuration" type = "web services. Services .configuration logging configuration" /> & Lt; / ConfigSections & gt; & Lt; Logging configuration string = "myConString" & gt; & Lt; / LoggingConfiguration & gt;  

logging configuration cs

  public seal class logging configuration: configuration sign {private contact stall connection ConnectionStringKey = "connectionString"; [Configuration property (connection string, isrequired = true)] public string connection string {return (string) base [connection string]; } Set {base [ConnectionStringKey] = value; }}}  

Global.asax.cs

  public override zero init () {base.Init (); Configuration configuration = Configuration Manager as the logging configuration ("logging configuration"); If (logging configuration! = Null) {New Jasonogar (logging configuration. Connection string) .net (this); }}  

In this way I can delete the following code in my web.config:

   & Lt; / HttpModules & gt; & Lt; /system.web> & Lt; System.webServer & gt; & Lt; Module & gt; & Lt; Add name = "Jasonolgor" type = "ServiceModel Logging .Jesolologer, Service Model" /> & Lt; / Module & gt; & Lt; /system.webServer>  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -