I am working on a sharepoint 2010 project and I noticed in the soultion their is no web.config.

I asked one of my fellow co-workers and he mentioned something about we don't have access to to it as sharepoint protects it due to security concerns.

I am wondering can I add another web.config(I don't see how I can add it as it is not in "add item") or what.

I would like to hook up elmah to do better logging. I need to setup some stuff in the web.config though.


I think this is what I need to add to the web.config

   <sectionGroup name="Elmah">
    <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
    <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
    <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
    <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
    <security allowRemoteAccess="1" />
    <!--<errorlog type="Elmah.XmlFilerErrorLog, Elmah" logPath="~/App_Data" />-->
    <errorLog type="Elmah.MemoryErrorLog, Elmah" size="50" />
     <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
     <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
     <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
     <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
     <add name="Elmah" verb="POST,GET,HEAD" path="elmah.axd" preCondition="integratedMode" type="Elmah.ErrorLogPageFactory, Elmah" />           

The problem is that in SharePoint, you have no idea how many web servers is running your site, and therefore you've no idea how many web.config's could be running (not you in particular, but in general, SharePoint can handle dozens of web front end servers). In order manage changes to the web.config file, the object model is design such that any and all modifications are performed safely and migrate to each and every server in the farm.

Yes it will be a lot of code for what you want to add, but it is the most secure method of doing it, and it will ensure your servers do not break (unless you do actually add some invalid code to the config file) from inconsistencies between servers.

Also, you can programmatically remove code from the web.config in the same API to ensure a graceful teardown of your solution.

Additionally, you cannot add a web.config to a Visual Studio 2010 solution like how you associate with Visual Studio 2008 web application projects - because SharePoint projects in VS2010 are not Web Application Projects. They are an enhanced form of Class Libraries which has an extra step which compresses your solution into SharePoint-compatible solution package which can be uniformly deployed to a supported SharePoint environment. For this reason also, there is no true "app.config" file in the solution. Therefore you have to adopt inventive methods of storing configurable options in SharePonint solutions, such as resource files or satellite assemblies.


It IS possible to include web.config files in a directory under the LAYOUTS folder (look at adding a Mapped Layouts folder) to your project, and anything you add in there is merged with the current web application's web.config file. This might seem the easiest option for you, but beware that this method will apply/merge the changes to EVERY web application in your farm. That might not be desirable.

-As pointed out by SPDoctor, this only works for application pages.

  • @James Love - I already have the layouts folder there. when I click to add an item to this folder. I don't see a web.config folder. – chobo2 Jun 2 '11 at 20:08
  • You'll need to just create a text file and rename it to web.config, and add your content into it. SharePoint is dumb when it comes to files placed here, it'll copy any and all files in regardless (including .svn files if you use tortoise SVN). – James Love Jun 2 '11 at 20:09
  • @James Love - So it will see web.config and try to match it and merge it with anything else called web.config? Can I un merge it after? Say I create that web.config and then don't want to have it merge anymore can I revert? – chobo2 Jun 2 '11 at 20:16
  • Not that I'm aware of, I believe this merging is an ASP.NET capability. If you don't want the file merged, you'd have to remove it from the Layouts folder (by retracting your solution) and recycle the application pool (an administration task, that may incur up to 30 seconds or so of downtime). – James Love Jun 2 '11 at 20:17
  • 1
    The web.config file in the LAYOUTS folder in the SharePoint root is used by your _layouts virtual directory, i.e. application pages. – SPDoctor Jun 2 '11 at 20:59

The config "template" files that are merged to create web.config files in the web root when web applications are provisioned are contained in the CONFIG directory in the SharePoint root (not LAYOUTS). The LAYOUTS folder in the SharePoint root is used by the _layouts virtual directory, i.e. application pages.

As well as making changes programmatically, you can create a supplemental config file and put it in the CONFIG folder, which may be easier if you have a lot of changes and you are able to modify your SharePoint root.


You can access the web.config using the object model, as seen here

  • I think that is kinda lot of data to do through code. (See Edit) – chobo2 Jun 2 '11 at 19:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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