views:

251

answers:

3

Hi

I am trying to use the debug and release versions of the webconfig but it never works. I am trying to do this for a 3rd party library that I am using called combres.

http://combres.codeplex.com/

So I first put all the needed web.config code in the web.config. Now I have 2 different .xml files(thats where you put your javascript and css paths).

So production will have a different .xml path and so will debug.

So I moved this one line to the release and debug of the web.config and changed the path of the xml file.

    // release webconfig
    <combres definitionUrl="~/App_Data/Combres.xml" />

   // debug webconfig
   <combres definitionUrl="~/App_Data/CombresDevelopment.xml" />

I get this

System.UnauthorizedAccessException was unhandled by user code
  Message=Access to the path 'E: test.com' is denied.
  Source=mscorlib
  StackTrace:
       at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
       at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
       at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
       at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials, IWebProxy proxy, RequestCachePolicy cachePolicy)
       at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
       at System.Xml.XmlReaderSettings.CreateReader(String inputUri, XmlParserContext inputContext)
       at System.Xml.XmlReader.Create(String inputUri, XmlReaderSettings settings, XmlParserContext inputContext)
       at System.Xml.Linq.XDocument.Load(String uri, LoadOptions options)
       at System.Xml.Linq.XDocument.Load(String uri)
       at Combres.ConfigReader.ReadCombresUrl(String filePath)
       at Combres.Configuration.GetCombresUrl()
       at Combres.WebExtensions.AddCombresRoute(RouteCollection routes, String name)
       at MyApp.MvcApplication.RegisterRoutes(RouteCollection routes) in E:\Global.asax.cs:line 19
       at MyApp3.MvcApplication.Application_Start() in E:\Global.asax.cs:line 46
  InnerException: 

line 19 -> routes.AddCombresRoute("Combres");

line 46 -> RegisterRoutes(RouteTable.Routes);

So I don't understand why I get this error. I thought the webconfig jsut get merged dynamically so why would it work on the top level on but not the .debug one.

Edit

Here is my files(some information removed for security concerns)

Web.config

    <configSections>
        <section name="combres" type="Combres.ConfigSectionSetting, Combres, Version=2.0.0.0, Culture=neutral, PublicKeyToken=49212d24adfbe4b4"/>
        <sectionGroup name="elmah">
            <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah"/>
            <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
            <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah"/>
            <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
            <section name="errorTweet" requirePermission="false" type="Elmah.ErrorTweetSectionHandler, Elmah"/>
        </sectionGroup>
    </configSections>

    <appSettings>....</appSettings>


    <!--<combres definitionUrl="~/App_Data/Combres.xml" />-->
    <!--<combres definitionUrl="~/App_Data/CombresDevelopment.xml" />-->

    <connectionStrings>....</connectionStrings>



    <elmah>
        <errorLog type="Elmah.SqlErrorLog, Elmah" logPath="~/App_Data" connectionStringName="...." />
        <errorFilter>
            <test>
                <equal binding="HttpStatusCode" value="404" type="Int32" />
            </test>
        </errorFilter>
        <security allowRemoteAccess="0" />
    </elmah>

    <system.web>
    <globalization culture="en" uiCulture="en-US" />
    <httpRuntime requestValidationMode="2.0"/>

    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </assemblies>
    </compilation>

    <authentication mode="Forms">
    </authentication>

    <pages>
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="CustomHtmlHelpers" />
        <add namespace="Combres.Mvc" />
      </namespaces>
    </pages>

      <httpHandlers>
          <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
      </httpHandlers>

      <httpModules>
          <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
          <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
          <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
          <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah"/>
      </httpModules>

  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

As you can see right now I have my combres commented out because right now I have to manually switch back and forth.

Here is my web.debug.config

<?xml version="1.0"?>

<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"&gt;
    <combres definitionUrl="~/App_Data/CombresDevelopment.xml"  xdt:Transform="Inserting"/>
    <!--
    In the example below, the "SetAttributes" transform will change the value of 
    "connectionString" to use "ReleaseSQLServer" only when the "Match" locator 
    finds an atrribute "name" that has a value of "MyDB".

    <connectionStrings>
      <add name="MyDB" 
        connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" 
        xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
    </connectionStrings>
  -->

  <system.web>        
      <!--
      In the example below, the "Replace" transform will replace the entire 
      <customErrors> section of your web.config file.
      Note that because there is only one customErrors section under the 
      <system.web> node, there is no need to use the "xdt:Locator" attribute.

      <customErrors defaultRedirect="GenericError.htm"
        mode="RemoteOnly" xdt:Transform="Replace">
        <error statusCode="500" redirect="InternalError.htm"/>
      </customErrors>
    -->
  </system.web>
</configuration>
A: 

I hope you must have already checked this. But just in case...

Right click APP_DATA folder. Check under security tab in Properties that the login under which IIS runs has appropriate permission to the APP_DATA folder.

Ismail
Well I put on every folder( including that one) to have a permission of "Everyone" and "Everyone" has full control. So do i have to add a different user?
chobo2
In most cases IIS runs under a login which is a member of `<machine name>\IIS_IUSRS` user group. You should give it a `write` permission.
Ismail
I gave that user full control and still same error.
chobo2
:( ................
Ismail
I think someone needs to make a sample on their computer using this library and see if they run into the same problem. This way I can get that copy and test out on my computer.
chobo2
+2  A: 

The way i understood it is that it does not merge, but transforms the web.config using a new syntax. There should be some comments in the release and debug configs with regards how to do this.

//In the example below, the "SetAttributes" transform will change the value of 
//"connectionString" to use "ReleaseSQLServer" only when the "Match" locator 
//finds an atrribute "name" that has a value of "MyDB".

<connectionStrings>
  <add name="MyDB" 
    connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" 
    xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>

As it says, this transform will replace the connection string, but im sure you could use it to transform and replace any other part of the web.config.


Try in your web.release.config

   <combres definitionUrl="~/App_Data/Combres.xml" xdt:Transform="SetAttributes"/>

And

web.debug.config

   <combres definitionUrl="~/App_Data/CombresDevelopment.xml" xdt:Transform="SetAttributes"/> 

I think your issue is with not using the transforms correctly, you can read this link for more information. http://blogs.msdn.com/b/webdevtools/archive/2009/05/04/web-deployment-web-config-transformation.aspx

Kohan
Ah well whatever it does it seems to need something more and I can't figure it out.
chobo2
I'm not entirely sure how you are modifying the web.config. What does your web.release.config look like. It should only contain things that you need to change for that build type.
Kohan
I can post it. See my edit. I tried to add that Transform(I tried replace, SetAttributes, Remove) but same error. If you could download combres and try by making your own sample and see if you get the same error that would be greatly appreciated.
chobo2
Also you said "need to change for that build type" do I have to launch it any special way or is F5(debug mode good enough to get the debug web.config?)
chobo2
Is this error occuring when you just press f5 (debug)? - If so, my solution will do nothing, i don't think those web.release.config etc are even used in that case (When debugging (f5) I reakon it uses your web.config as it is and will not apply any transforms). The web.release.config etc will only be used when you use publishing. See http://weblogs.asp.net/owscott/archive/2009/06/06/visual-studio-2010-1-click-publishing.aspx is this what you are doing, or just debugging with F5?
Kohan
I am trying to use the debug one of the web.config. When would that one run then if not when debuging. No the error does not happen I press F5 everything complies fine and runs. It crashes once it starts to go global.aspx line when trying to load up a view on the very first line it hits in the global.aspx routes.AddCombresRoute("Combres");
chobo2
So it's not working when you (F5) debug; as when you hit a view it is breaking. I think there's a little confusion here. I don't think you need to be using the release and debug configs, they won’t be doing anything for you here. The error will be somewhere else, either in your global.asax, the web.config (the real one, bear in mind this will not be affected by the release and debug configs) or in your Combres.xml. Does this open source project have a forum? I suggest asking there for some ideas. Sorry I couldn't help more. My response assumed it was working and you had problems publishing.
Kohan
It is working when I hit F5 it does not work when the site launches and starts to load. The reason why I want to use 2 different web.configs is then I can switch between .xml files one for development and one for production. I don't know where the problem is happening all I know is that when I move that one line from web.config to web.debug.config I get errors when the page is loading.
chobo2
+1  A: 

Is appears not a web.config issue.

The error is about not having access to 'E: test.com' path.

Check the permission on this file and the error should vanish, or uncover the real error.

Regards

jaderanderson
Just to add, check the permissions directly on the files not on the folders. Sometimes coping files around mess with the security Ex: Having a permission set in a folder, but copy a file with diferent directives inside... the folder will be avaliable but the file wont.
jaderanderson
Ok I checked the permissions on the files they had a permission of everyone and everyone got full control. I added iis_Iusrs as well and gave full control. But I get the same error. I really think someone needs to actual make quick test on their computer and try it out. That way if it works it can be sent to me and I try it out and compare what is different.
chobo2