Web.config conflict

Topics: ASP.NET 2.0
Mar 30, 2008 at 6:43 PM
Hello,I am having problem when I place my blogengine on virtual directory under my main website which I got from asp.net.(personal web site starter kit).Anyways when I move blog as a separate web site it works fine but as a virtual directory it will not work.It somehow conflicts with the web.config from the main website but i dont know how to fix this.Any help would be greatly appreciated.Thank you.
Mar 30, 2008 at 8:56 PM
I have also noticed that my default.aspx for blog is trying to use the web.config of parent application(website).i see this from the error I am getting..
Apr 1, 2008 at 10:44 AM
Edited Apr 1, 2008 at 10:49 AM
In your parent web.config file you can try:

wrap your <system.web> section with <location path="." inheritInChildApplications="false">

<location path="." inheritInChildApplications="false">
<!--all the usual or unusual stuff-->

...or you can add the offending overrides to your VD web.config. For instance if the only issue is BE complaining of not finding the theme add a theme or styleSheetTheme to the web.config.
<pages enableSessionState="false" enableViewStateMac="true" enableEventValidation="true" styleSheetTheme="">

Apr 2, 2008 at 2:00 AM
Edited Apr 2, 2008 at 2:30 AM
Thank you very much for your reply.These webconfig files are so annoying..:)..at least for users like me.I tried to modify it with your instructions but now it says inheritInChildApplications attribued is not declared not much change with errors.I just dont get how virtual path not looking it's webconfig first but parent webconfig.Am I missing something? Thanks again.
Below I attach two web.config files if it helps any.

<?xml version="1.0"?>
<add name="Personal" connectionString="Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|Personal.mdf" providerName="System.Data.SqlClient" />
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|aspnetdb.mdf" />

<pages styleSheetTheme="White"/>
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
<compilation debug="false"/>
<authentication mode="Forms">
<forms loginUrl="Default.aspx" protection="Validation" timeout="300" />
<allow users="*"/>
<globalization requestEncoding="utf-8" responseEncoding="utf-8"/>
<roleManager enabled="true"/>

<siteMap defaultProvider="XmlSiteMapProvider" enabled="true">
<add name="XmlSiteMapProvider"
description="SiteMap provider which reads in .sitemap XML files."
type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

<location path="Admin">
<allow roles="Administrators"/>
<deny users="*"/>

Apr 2, 2008 at 2:29 AM

<?xml version="1.0"?>

<sectionGroup name="BlogEngine">
<section name="blogProvider" requirePermission="false" type="BlogEngine.Core.Providers.BlogProviderSection, BlogEngine.Core" allowDefinition="MachineToApplication" restartOnExternalChanges="true"/>

<blogProvider defaultProvider="XmlBlogProvider">
<add name="XmlBlogProvider" type="BlogEngine.Core.Providers.XmlBlogProvider, BlogEngine.Core"/>
<add name="MSSQLBlogProvider" type="BlogEngine.Core.Providers.MSSQLBlogProvider, BlogEngine.Core"/>

<!-- configSource is not implemented in Mono.
<connectionStrings configSource="sql.config" />

<clear />
<add name="LocalSqlServer" connectionString="dummy" />

<add key="BlogEngine.FileExtension" value=".aspx" />
<!-- You can e.g. use "~/blog/" if BlogEngine.NET is not located in the root of the application -->
<add key="BlogEngine.VirtualPath" value="/" />
<!-- The regex used to identify mobile devices so a different theme can be shown -->
<add key="BlogEngine.MobileDevices" value="(nokia|sonyericsson|blackberry|samsung|sec-|windows ce|motorola|mot-|up.b)" />


<compilation debug="true" />
<globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="auto" uiCulture="auto" />
<httpRuntime enableVersionHeader="false" useFullyQualifiedRedirectUrl="true" maxRequestLength="16384" executionTimeout="3600" requestLengthDiskThreshold="16384" />
<trust level="High" />

validation="SHA1" decryption="AES"

<authentication mode="Forms">
<forms timeout="129600" name=".AUXBLOGENGINE" protection="All" slidingExpiration="true" loginUrl="~/login.aspx" cookieless="UseCookies" />

<pages enableSessionState="false" enableViewStateMac="true" enableEventValidation="true">
<add namespace="Controls" tagPrefix="blog"/>

<customErrors mode="RemoteOnly">
<error statusCode="404" redirect="~/error404.aspx" />

<membership defaultProvider="XmlMembershipProvider" >
<clear />
<add name="XmlMembershipProvider" type="BlogEngine.Core.Providers.XmlMembershipProvider, BlogEngine.Core" description="XML membership provider" xmlFileName="~/App_Data/users.xml"/>

<roleManager defaultProvider="XmlRoleProvider" enabled="true" cacheRolesInCookie="true" cookieName=".BLOGENGINEROLES">
<clear />
<add name="XmlRoleProvider" type="BlogEngine.Core.Providers.XmlRoleProvider, BlogEngine.Core" description="XML role provider" xmlFileName="~/App_Data/roles.xml"/>

<siteMap defaultProvider="PageSiteMap" enabled="true" >
<add name="PageSiteMap" description="The site map provider that reads in the .sitemap XML files." type="BlogEngine.Core.Web.Controls.PageSiteMap, BlogEngine.Core"/>
<add name="SecuritySiteMap" description="Used for authenticated users." type="System.Web.XmlSiteMapProvider, System.Web, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" securityTrimmingEnabled="true" siteMapFile="Web.sitemap" />

<add name="WwwSubDomainModule" type="BlogEngine.Core.Web.HttpModules.WwwSubDomainModule, BlogEngine.Core"/>
<add name="UrlRewrite" type="BlogEngine.Core.Web.HttpModules.UrlRewrite, BlogEngine.Core"/>
<add name="CompressionModule" type="BlogEngine.Core.Web.HttpModules.CompressionModule, BlogEngine.Core"/>
<add name="ReferrerModule" type="BlogEngine.Core.Web.HttpModules.ReferrerModule, BlogEngine.Core"/>
<!--The CleanPageModule below removes whitespace which makes the page load faster in IE. Enable at own risk -->
<!--<add name="CleanPageModule" type="BlogEngine.Core.Web.HttpModules.CleanPageModule, BlogEngine.Core"/>-->

<!--Remove the default ASP.NET modules we don't need-->
<remove name="PassportAuthentication" />
<remove name="Profile" />
<remove name="AnonymousIdentification" />

<add verb="*" path="file.axd" type="BlogEngine.Core.Web.HttpHandlers.FileHandler, BlogEngine.Core" validate="false"/>
<add verb="*" path="image.axd" type="BlogEngine.Core.Web.HttpHandlers.ImageHandler, BlogEngine.Core" validate="false"/>
<add verb="*" path="syndication.axd" type="BlogEngine.Core.Web.HttpHandlers.SyndicationHandler, BlogEngine.Core" validate="false"/>
<add verb="*" path="sitemap.axd" type="BlogEngine.Core.Web.HttpHandlers.SiteMap, BlogEngine.Core" validate="false"/>
<add verb="*" path="trackback.axd" type="BlogEngine.Core.Web.HttpHandlers.TrackbackHandler, BlogEngine.Core" validate="false"/>
<add verb="*" path="pingback.axd" type="BlogEngine.Core.Web.HttpHandlers.PingbackHandler, BlogEngine.Core" validate="false"/>
<add verb="*" path="opensearch.axd" type="BlogEngine.Core.Web.HttpHandlers.OpenSearchHandler, BlogEngine.Core" validate="false"/>
<add verb="*" path="metaweblog.axd" type="BlogEngine.Core.API.MetaWeblog.MetaWeblogHandler, BlogEngine.Core" validate="false"/>
<add verb="*" path="rsd.axd" type="BlogEngine.Core.Web.HttpHandlers.RsdHandler, BlogEngine.Core" validate="false"/>
<add verb="*" path="css.axd" type="BlogEngine.Core.Web.HttpHandlers.CssHandler, BlogEngine.Core" validate="false"/>
<add verb="*" path="js.axd" type="BlogEngine.Core.Web.HttpHandlers.JavaScriptHandler, BlogEngine.Core" validate="false"/>
<add verb="*" path="rating.axd" type="BlogEngine.Core.Web.HttpHandlers.RatingHandler, BlogEngine.Core" validate="false"/>
<add verb="*" path="opml.axd" type="BlogEngine.Core.Web.HttpHandlers.OpmlHandler, BlogEngine.Core" validate="false"/>
<add verb="*" path="monster.axd" type="BlogEngine.Core.Web.HttpHandlers.MonsterHandler, BlogEngine.Core" validate="false"/>
<add verb="*" path="blogml.axd" type="BlogEngine.Core.Web.HttpHandlers.BlogMLExportHandler, BlogEngine.Core" validate="false"/>

Apr 2, 2008 at 10:07 AM
You can get an overview of the web.config inheritance from http://msdn2.microsoft.com/en-us/library/ms178685.aspx.
Basically in a nutshell, unless you specifically override a child web.config it will inherit from the parent all the way up to the line including the server config. It is not recommended to nest virtual directories for this exact reason.

Don't be concerned with the not declared error. What is your exact error when you use?

<location path="." inheritInChildApplications="false">
<!--all the usual or unusual stuff-->

Is the error identical or did it change complaining about something else?

Assuming you cannot setup BE on a subdomain, another foolproof option would be to move your main app into it's own virtual directory so you do not need a web.config in the root. You can then setup a redirect on a default.aspx in the root to the new main virtual directory.
Apr 3, 2008 at 1:36 AM
It's giving me this error now after I put <location path="." inheritInChildApplications="false">.settings.xml is actually under D:\Blog folder.So I am not sure why it's looking under main application folder.Thanks again.

Could not find file 'C:\ErolWeb\App_Data\settings.xml'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileNotFoundException: Could not find file 'C:\ErolWeb\App_Data\settings.xml'.
Apr 3, 2008 at 9:56 AM
You lost me now, I run a lot of BE installs in subdirectories as applications and I never have any problems once I correct a few inheritance issues in the web.configs.
Sorry I couldn't be of more help. Let's hope someone else can step in here that has seen that one before.
Good luck.
Apr 3, 2008 at 10:11 AM
I did not totally give up but this won't be very helpful either. I fired up a PWS in C# and added BE 1.3 to it at ~/Blog configured as an application. I modified the BE web.config and added styleSheetTheme="" to the pages directive to overide the white theme of PWS. Gave Network Service modify permissions on the app_data folder and all is well with the world. Both apps work perfectly.