SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have developed a webservice using the following tutortial

This webservice requires to pick some values from web.config file like

    <add key="OracleDataSource" value="ORCL"/>
    <add key="UserID" value="scott"/>
    <add key="Password" value="scott54321"/>

and inside the methods which requires database connectivity using the above 3 key values to establish connections. So how to add web.config in layouts folder and pick values..also need to know that this webservice will be deployed on production later. Also I read somewhere that whenever you make changes in web.config anywhere it reverts to keep this change permanent as my guys dont want to go into hassle of creating feature..they want to update the key values by hand in web.config and webservice reads the current value.

share|improve this question
where did you read this "whenever you make changes in web.config anywhere it reverts back." ? – Muhammad Raja Mar 17 '13 at 10:40
up vote 0 down vote accepted

I never seen anything like web.config file in layouts folder, so I would assume its simply not best practice neither counted as recommended way of doing it and you might end up with several problems no one know about.

Anyway your basic requirement is that you need to add a web.config because your client (bank) needs to change password periodically, so why don't you keep password or settings in a database and use a utility class to fetch it as if your client will have permissions to edit web.config on WFEs then I think they should have given permission to a custom database with custom permissions on it.

Another way I can think of is create a simple xml file with tags for user and password and then in your feature activated code as provided by rjcup3 in this answer Custom SharePoint 2010 WebService inside /_vti_bin and web.config , you can get easily values using XmlTextReader.

Make sure XML file will have appropriate permissions. Using XML file for storing credentials you won't need to recompile your project as with web.config, if you make changes to web.config "in your case only as web.config will reside within assembly".

For the second part you can read application configuration using this code line,

textBox1.Text = ConfigurationManager.AppSettings["OracleDataSource"];
textBox2.Text = ConfigurationManager.AppSettings["UserID"];
textBox3.Text = ConfigurationManager.AppSettings["Password"];

But you will need to make sure your project has reference to System.Configuration.dll

if you want to read more check the following links out,

MSDN article on reading app settings

Edited for Comment

You can have credentials saved in a XML file which can be placed anywhere on your server's drive I would personally create a new folder in drive which is used for applications and put file in a root directory then in 12 hive for ease to edit, and then in web method you can call it, but make sure only right people will have permissions on file for viewing and then editing respectively. Deployments I worked on always kept credentials in a separate utility class for security purposes but they didn't wanted to change it that often and if they change it, they had to re-doply changes which means downtime.

In short by using a XML file you will not require any downtime if you will update credentials.

share|improve this answer
Raja, you cleared my after reading your answer I went into ISAPI folder and noticed there was only ASMX and no web.config was there so how come they can you said in my case whenever there is a change required there will be a need of recompiling and new deployment..well i am not that proficient as I am learning by time. So you mean i need to create a simple XML instead of web.config under layouts..and perhaps can read xml nodes from webservice methods? my webservice has methods which is calling database so to reach database i need credentials stores in config or from xml.. – user342944 Mar 17 '13 at 11:56
@user342944 I updated my answer – Muhammad Raja Mar 17 '13 at 12:45
Raja, I did what you said..the xml is under my layouts/CustomWS folder called credentialsxml.xml and when i try to read it i am getting "System.Net.WebException: The remote server returned an error: (401) Unauthorized. at System.Net.HttpWebRequest.GetResponse() can you guide what permissions do i need there..this webservice will be called by 3rd party vendor also to pass oracle data which is going into my SharePoit LISTS so keep this in mind for the required permission – user342944 Mar 17 '13 at 12:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.