Accessing Web.Config from a separate solution http://forums.asp.net/t/1785869.aspx/1?Accessing+Web+Config+from+a+separate+solution+Mon, 02 Apr 2012 13:19:31 -040017858694902062http://forums.asp.net/p/1785869/4902062.aspx/1?Accessing+Web+Config+from+a+separate+solution+Accessing Web.Config from a separate solution <p>Hi,<br> <br> I have two solutions, one is a class library and the other is a web application, and I want to get the connection string from the web.config file to the class library as I am developing a custom membership provider. I am using Framework 4.0 and MS Visual Studio 2010.&nbsp;</p> <p></p> <p>Thanks</p> 2012-03-27T15:42:03-04:004902073http://forums.asp.net/p/1785869/4902073.aspx/1?Re+Accessing+Web+Config+from+a+separate+solution+Re: Accessing Web.Config from a separate solution <p>you should be able to use</p> <p>ConfigurationManager.AppSettings[&quot;KeyName&quot;]</p> <p><span class="pln">inside class library project and it should read web.config file of refernecing asp.net web project</span></p> <p><span class="pln">hope this helps...<br> </span></p> 2012-03-27T15:47:11-04:004902151http://forums.asp.net/p/1785869/4902151.aspx/1?Re+Accessing+Web+Config+from+a+separate+solution+Re: Accessing Web.Config from a separate solution <p>Where you put &quot;KeyName&quot; I put the connection string name?</p> 2012-03-27T16:24:48-04:004902176http://forums.asp.net/p/1785869/4902176.aspx/1?Re+Accessing+Web+Config+from+a+separate+solution+Re: Accessing Web.Config from a separate solution <p></p> <blockquote><span class="icon-blockquote"></span> <h4>Coqmos</h4> <p></p> <p>Where you put &quot;KeyName&quot; I put the connection string name?</p> <p></p> </blockquote> <p></p> <p>Yes...</p> <p>suppose web.config of asp.net web project has conenction string as</p> <p><span class="punct">&lt;</span><span class="ident">connectionStrings</span><span class="punct">&gt;</span><br> &nbsp;&nbsp; <span class="punct">&lt;</span><span class="ident">add</span> <span class="ident"> name</span><span class="punct">=&quot;</span><strong><span class="string">ConnectionString</span></strong><span class="punct">&quot;</span> <span class="ident">connectionString</span><span class="punct">=&quot;your </span><span class="string">connection string details</span><span class="punct">&quot;</span> <span class="punct">/&gt;</span><br> <span class="punct">&lt;/</span><span class="regex">connectionStrings&gt;<br> <span class="normal"><br> then, in class library project u can read it as</span></span></p> <p><span class="regex"><span class="normal"><span class="constant">string strCon = System</span><span class="punct">.</span><span class="ident">Configuration</span><span class="punct">.</span><span class="ident">ConfigurationManager</span><span class="punct">.</span><span class="ident">ConnectionStrings</span><span class="punct">[&quot;</span><strong><span class="string">ConnectionString</span></strong><span class="punct">&quot;].</span><span class="ident">ConnectionString;</span></span></span></p> <p><span class="regex"><span class="normal"><span class="ident">hope this helps...</span></span></span></p> 2012-03-27T16:36:52-04:004902278http://forums.asp.net/p/1785869/4902278.aspx/1?Re+Accessing+Web+Config+from+a+separate+solution+Re: Accessing Web.Config from a separate solution <p>Yes but the web.config file is not in the same solution and not in the same directory also so I need to add some kind of reference I think to iy</p> 2012-03-27T17:39:58-04:004902400http://forums.asp.net/p/1785869/4902400.aspx/1?Re+Accessing+Web+Config+from+a+separate+solution+Re: Accessing Web.Config from a separate solution <p></p> <blockquote><span class="icon-blockquote"></span> <h4>Coqmos</h4> <p></p> <p>Yes but the web.config file is not in the same solution and not in the same directory also so I need to add some kind of reference I think to iy</p> <p></p> </blockquote> <p></p> <p>suppose u r simple creating a class library (dll) then u can use this code to read web.config connectionstring...</p> <p>when u add this dll in web application project, this code would read web.config where this dll is referenced</p> <p>hope this helps...</p> 2012-03-27T18:58:31-04:004910524http://forums.asp.net/p/1785869/4910524.aspx/1?Re+Accessing+Web+Config+from+a+separate+solution+Re: Accessing Web.Config from a separate solution <p>Hi,</p> <p></p> <p>Sorry For the late reply but I was away and did not have time to respond, jus to check, if in my dll I Do<br> <br> connString = <span class="constant">System</span><span class="punct">.</span><span class="ident">Configuration</span><span class="punct">.</span><span class="ident">ConfigurationManager</span><span class="punct">.</span><span class="ident">ConnectionStrings</span><span class="punct">[&quot;ApplicationString</span><span class="punct">&quot;].</span><span class="ident">ConnectionString;</span>&nbsp;</p> <p>It should get the connection string?<br> <br> Sorry but as you can see I am still a Beginner.</p> <p>Thanks A Lot and I apolagize again for the late reply&nbsp;</p> 2012-04-01T16:13:28-04:004910887http://forums.asp.net/p/1785869/4910887.aspx/1?Re+Accessing+Web+Config+from+a+separate+solution+Re: Accessing Web.Config from a separate solution <p></p> <blockquote><span class="icon-blockquote"></span> <h4>Coqmos</h4> <p></p> <p>Hi,</p> <p></p> <p>Sorry For the late reply but I was away and did not have time to respond, jus to check, if in my dll I Do<br> <br> connString = <span class="constant">System</span><span class="punct">.</span><span class="ident">Configuration</span><span class="punct">.</span><span class="ident">ConfigurationManager</span><span class="punct">.</span><span class="ident">ConnectionStrings</span><span class="punct">[&quot;ApplicationString</span><span class="punct">&quot;].</span><span class="ident">ConnectionString;</span>&nbsp;</p> <p>It should get the connection string?</p> <p></p> </blockquote> <p></p> <p>Yes... it should</p> <p>why dont u try</p> <p>hope this helps...</p> 2012-04-02T05:02:50-04:004911972http://forums.asp.net/p/1785869/4911972.aspx/1?Re+Accessing+Web+Config+from+a+separate+solution+Re: Accessing Web.Config from a separate solution <p>Thanks Very Much For your Help it worked out Great<br> <br> Thanks Again For your help <img src="http://forums.asp.net/scripts/tiny_mce/plugins/emotions/img/smiley-laughing.gif" alt="Laughing" title="Laughing" border="0">&nbsp;&nbsp;</p> 2012-04-02T13:19:31-04:00