How do I configure this IIS 7.5 child application properly? - c#

I have a parent application hosted in the root folder of my website. It's a .NET 4.0 application and the application pool is obviously set to 4.0.
I want to configure a child application at:
/blog
This is a .NET 2.0 application (it's BlogEngine.NET). I created a new virtual directory called "blog", pointed it at the appropriate directory, converted it to an application and put it in it's own application pool set to .NET Framework 2.0.
I edited the parent web.config and added:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
....entire web.config basically...
</location>
</configuration>
Right after the element. However, when I go to http://localhost/blog, I get the following error:
The configuration section 'configSections' cannot be read because it is missing a section declaration
Anyone have any ideas what's going on here or what I might be missing?

Unfortunately this is a downfall of the way IIS handles virtual directories. Your parent application's web.config is still read even though it's not in the child application. I tried to nest a 4.0 app as a child of a 3.5 app before and after several days of frustration, SO questions, and forum posts, I finally came to the conclusion that it was more trouble than it was worth.

Why don't you just upgrade BlogEngine to Asp.net 4.0 ?
Download the BE 2.0 Web version open it up in Visual Studio it will ask "Would you like it 4.0?" Say yes then it targets the web.config for you.
You can then just upload the new web.config to your server.
If you have an old BE version then you might want to upgrade it to the last stable release.

Related

How do I force IE to load site with .net framework 3.5?

I have a web app then needs framework 3.5 to run. A system update keeps installing framework 4.5, this breaks the web app. I updated the web.config and even tried an app config for IE (config listed below). But neither work, I downloaded processactivityview tool to see what was going on. It seems to load framework 4.5 before reading the config file.
How can I force the IE to load this page with framework 3.5?
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v2.0.50727"/>
</startup>
</configuration>
If you have access to IIS, create new Application Pool in IIS for FW 3.5 and assign your app to it.

Can I make a monoSettings section in a web.config file optional to run on Windows as well as under Mono?

I have had to add a monoSettings section to my Web.config file as I need to support colons in the url (similar to this question: ASP.NET special characters in URL (colon) not working even with requestPathInvalidCharacters="").
Now when I run my web-api service in visual studio (which I do for ad-hoc testing) it gives an error:
"The configuration section 'monoSettings' cannot be read because it is missing a section declaration"
I'm just wondering what is the best way to support this config in my Mono service without impacting being able to run in on Windows? Can I just flag it as optional or unimportant so that it won't fail when trying to read the config? Or is it just better to have a different build configuration for Mono - but I'd then have to maintain two versions of web.config with just this one minor difference.
I resolved this issue by adding a configSection to my Web.config as follows:
<configuration>
<configSections>
<sectionGroup name="system.web">
<section name="monoSettings" type="DataSetSectionHandler,SectionHandlers" />
</sectionGroup>
</configSections>
<system.web>
<monoSettings verificationCompatibility="1" />
<httpRuntime requestPathInvalidCharacters="<,>,*,%,&,\,?" />
</system.web>
</configuration>

How to programatically update custom attribute in app config file

My app.config.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
</configSections>
<Something SettingsLocation="D:\test\test\file.json" />
<Something />
</configuration>
I need to update SettingsLocation programatically.
I found this some answers, but it is not clear to me.
Thanks fo help.
Each application has it’s own configuration file, be it a windows based application or web based.
This application configuration file defines information which can be used by application to make decisions, to load some other information or may contain the custom configuration which can be empowered to do anything.
There can also be scenarios where an application may want to change\modify the existing setting in the application configuration file and those changes should not only take effect immediately but should also be persisted.
Possible solution is already shown here

C# and Razor - The type of page you have requested is not served because it has been explicitly forbidden. The extension '.cshtml' may be incorrect

I have looked through other posts but none seem to answer what I need.
I created an empty site in WebMatrix (ASP.NET)
I opened that site in VWD 2013
I hit F5 and it runs fine on a URL such as http://local.com:59833/ContentPage.cshtml
I go to http://local.com/cscsu_bi/ContentPage.cshtml and it doesn't work with the error below
Server Error in '/' Application.
This type of page is not served.
Description: The type of page you have requested is not served because it has been explicitly forbidden. The extension '.cshtml' may be incorrect. Please review the URL below and make sure that it is spelled correctly.
Requested URL: /cscsu_bi/ContentPage.cshtml
The web.config file is as follows
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="webpages:Enabled" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
</configuration>
I am on Windows 7. Is there anything obvious I'm doing wrong?
Thanks
I was missing the Microsoft.AspNet.WebPages NuGet package. Installing it solved my problem. (This package has dependencies on Microsoft.Web.Infrastructure and Microsoft.Web.Razor and thus includes them for you)
If you use the NuGet console, just type:
Install-Package Microsoft.AspNet.WebPages
I have set up Razor on a number of machines, and often find that I need to include the following DLLs in my bin folder:
System.Web.Razor.dll
System.Web.WebPages.Deployment.dll
System.Web.WebPages.dll
System.Web.WebPages.Razor.dll
Microsoft.Web.Infrastructure.dll
Take a look at this article.
http://www.asp.net/web-pages/overview/more-resources/aspnet-web-pages-(razor)-troubleshooting-guide
This fixed my issue after reviewing all IIS settings and references.
Make sure that the root of your website has at least one .cshtml file in it.
This may not be your exact issue, but I have had this happen for a couple reasons:
Incorrect Framework on Server: Make sure the target framework of the
project is supported by the server. Just changing the
targetFramework attribute of the compilation element may not be
enough as the DLLs for your project may be compiled
against the 4.5 framework.
Incorrect Framework of Application Pool: This can also happen if
your application pool is not using the right .Net CLR version. Make
sure it is using the 4.0 instead of 2.0
In my case the culprit was the fact that Global.asax was placed under the '/Views' folder. This was somehow working while the project was targeting MVC3. Once the solution got upgraded to MVC4, running said solution would result in the aforementioned errors. In a similar vein, other errors would crop up mentioning:
"no default webpage has been set and directory browsing has been disabled"
The solution: After upgrading to MVC4+ I had to manually move Global.asax under the root folder of the container project. Be sure to inspect Global.asax to make sure that the namespace applied within is the proper one. Just my 2c.
In my case I set webpages:Enabled to true under appSettings:
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
According to post: what is the function of webpages:Enabled in MVC 3 web.config, this prevents files in the Views folder from being directly accessible from a web browser.

How to prevent inheritance for web.config file for "configSections"?

I have following in my parent web applications config file
<configuration>
<configSections>
<sectionGroup name="testmodule">
<section name="testmodule" type="RewriteModule.RewriteModuleSectionHandler, RewriteModule"/>
</sectionGroup>
</configSections>
</configuration>
i want to prevent child subfolders from inheriting this config section where should i put
<location path="." inheritInChildApplications="false">, since config sections should be first child element of configuration file
This has been answered a couple of times on SO, but incorrectly in my opinion.
The docs, are pretty clear (1)(2):
The following example shows how to use
this attribute in a configuration file
to specify that the settings defined
in the location element for the root
of a Web site should not be inherited
by child applications:
The InheritInChildApplications
property applies only to
location-specific configuration
settings.
To answer your question, this should suffice:
<configuration>
...
<sectionGroup name="testmodule">
<section name="testmodule" type="RewriteModule.RewriteModuleSectionHandler, RewriteModule"/>
</sectionGroup>
...
<location path="." inheritInChildApplications="false">
<testModule>
....
</testModule>
</location>
(1) - http://msdn.microsoft.com/en-us/library/system.configuration.sectioninformation.inheritinchildapplications.aspx
(2) - http://msdn.microsoft.com/en-us/library/ms178692.aspx
Seems to be no solution for this currently, should avoid using conflicting section groups in web.config file.
If you use a different name in the conflicting child section it will not clash with the parent and you can reference both sections in their respective web.config files using the different names..
its not perfect but its a work around i've used with success....
We're getting errors about duplicate configuration directives on the one of our apps.
After investigation it looks like it's because of this issue.
In brief, our root website is ASP.NET 3.5 (which is 2.0 with specific libraries added), and we have a subapplication that is ASP.NET 4.0.
web.config inheritance causes the ASP.NET 4.0 sub-application to inherit the web.config file of the parent ASP.NET 3.5 application.
However, the ASP.NET 4.0 application's global (or "root") web.config, which resides at C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.config and C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config (depending on your bitness), already contains these config sections.
The ASP.NET 4.0 app then tries to merge together the root ASP.NET 4.0 web.config, and the parent web.config (the one for an ASP.NET 3.5 app), and runs into duplicates in the node.
The only solution I've been able to find is to remove the config sections from the parent web.config, and then either
Determine that you didn't need them in your root application, or
Upgrade the parent app to ASP.NET 4.0 (so it gains access to the root web.config's configSections)
i have the same situation than you as my root Application is using an AppPool of .net 2.0 and child AppPool is .Net 4.0. I solved using the suggestion in "Entry has already been added" - Two Separate App Pools, by setting both AppPools to enableConfigurationOverride="false" it works like a charm.

Categories