Re: Connection string issue when in a separate web.config



This all worked for Asp.NET 2.0. Now, can someone tell me how to do this in
Asp.NET 1.1?

"Dominick Baier [DevelopMentor]" wrote:

your application identity needs read access to the config file - thats by
default NETWORK SERVICE

---------------------------------------
Dominick Baier - DevelopMentor
http://www.leastprivilege.com

Your answer worked. However, now I need to know how to configure
permissions on the Secure directory.

We are using Windows 2003, and IIS6. What do we need to do regarding
permissions for the Secure folder.

"Dominick Baier [DevelopMentor]" wrote:

hi,

the indexer on .ConnectionStrings expects the name of the connection
string, in your case "myConnectionString".

that said - which config entries
WebConfigurationManager/ConfigurationManager can "see" depends on the
location from where they were called

if you want to access the connection string that is stored in
~/secure from ~/someOtherDir - this want work e.g.

you can explicitly open the config file

Configuration c =
WebConfigurationManager.OpenWebConfiguration("~/secure"); return
c.ConnectionStrings.ConnectionStrings["data"].ConnectionString;

or just store the connection string in the root directory where it
will be used...

---------------------------------------
Dominick Baier - DevelopMentor
http://www.leastprivilege.com
Using asp.net 2.0, visualstudio .net 2005, sqlserver2000.

How do I get the myConnectionString when it is in a Web.Config
located in a different folder. I used the following but it is not
working.

I have a App_Code\DAL folder. Inside it, I have a Db.cs file. I
tried the following in the DB.cs file.

//Get default connection string
connectionString =
WebConfigurationManager.ConnectionStrings["~/Secure/myConnectionStri
ng
"].ConnectionString;
I have created a folder inside my website folder, named Secure, and
placed a web.cofig file that contains the following in the Secure
folder.
<?xml version="1.0"?>
<configuration
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0";>
<appSettings/>
<connectionStrings>
<add name="myConnectionString"
connectionString="Data
Source=MyDomain\MyServerName;Database=MydatabaseName;uid=xxx;pwd=xx;
"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
</system.web>
</configuration>
My website contains a web.config file with the following contents:
<?xml version="1.0"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0";>
<appSettings/>
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true"/>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows"/>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly"
defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
</system.web>
<system.net>
<mailSettings>
<smtp from="">
<network host="smtp.myServer.com" password="" userName="" />
</smtp>
</mailSettings>
</system.net>
</configuration>



.



Relevant Pages

  • Re: ADC remove
    ... The folder being there is not an issue as long as no connection are ... Microsoft Exchange Support Engineer ... connections" from microsoft exchange under services of configuration ...
    (microsoft.public.exchange.admin)
  • Re: version/source control in datawarehouse project
    ... I gather all datasourcesin DataSource folder and put *.dtsx ... So if the db connection on developer's machine is different from ... that means developer has to modify all conn string in all dtsx.... ... you can use configuration files to store your database connections. ...
    (microsoft.public.sqlserver.datawarehouse)
  • Re: Connection string issue when in a separate web.config
    ... But the normal configuration inheritance rules apply. ... Dominick Baier - DevelopMentor ... regarding permissions for the Secure folder. ... connection string, in your case "myConnectionString". ...
    (microsoft.public.dotnet.security)
  • Re: Connection string issue when in a separate web.config
    ... Dominick Baier - DevelopMentor ... permissions on the Secure directory. ... the indexer on .ConnectionStrings expects the name of the connection ... Configuration c = ...
    (microsoft.public.dotnet.security)
  • Connection string issue when in a separate web.config
    ... I have a App_Code\DAL folder. ... //Get default connection string ... the Website->Asp.Net Configuration option in Visual Studio. ... The section enables configuration ...
    (microsoft.public.dotnet.security)