Enabling URL Rewriting with ASP.NET using web.config

Ben Carey picture Ben Carey · Jan 24, 2013 · Viewed 20.3k times · Source

I am brand new to ASP.NET, in fact I know pretty much nothing about it, but do not despair, I am not looking for a tutorial... A colleague of mine is wanting to run an ASP.NET application on our Webserver. Our Webserver is running Windows 2008 R2, with Plesk 11 and IIS 7.5.

So far I have had all sorts of problems trying to enable ASP.NET, but after a lot of fiddling around, I managed to get the application working (to a certain extent).

However, in order to get the application to work, I had to remove the following lines from my web.config file:

<configSections>
    <sectionGroup name="system.webServer">
        <sectionGroup name="rewrite">
            <section name="rewriteMaps" overrideModeDefault="Allow" />
            <section name="rules" overrideModeDefault="Allow" />
        </sectionGroup>
    </sectionGroup>
</configSections>

This was because I was receiving the error:

Parser Error Message: Section or group name 'system.webServer' is already defined. Updates to this may only occur at the configuration level where it is defined.

My folder structure is like so:

website/
    TestApplication/
        web.config
    index.php
    web.config

I have created an Application for the folder 'TestApplication' (not that I really know what this means), but this has not made any difference.

I was under the impression that if you create an application, the web.config inside the directory will not inherit any of the parent configurations! This does not seem to be the case here as I am still receiving the error.

My question is, what am I meant to do with the above situation? How can I either prevent the application from inheriting the parent directories configurations, or alternatively, fix the current web.config file to work with ASP.NET?

One thing to note, I have made changes in both IIS Manager, and Plesk as I was unable to find particular things in the Plesk Control Panel, for instance: creating an application for a directory within a website. I don't think this is the cause of the issue here, but nevertheless, worth mentioning.

UPDATE

This is my full web.config file (with all bar one of my rules removed as they have no impact on the file):

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

<configSections>
    <sectionGroup name="system.webServer">
        <sectionGroup name="rewrite">
            <section name="rewriteMaps" overrideModeDefault="Allow" />
            <section name="rules" overrideModeDefault="Allow" />
        </sectionGroup>
    </sectionGroup>
</configSections>

    <system.webServer>
        <httpErrors errorMode="Detailed" />
        <asp scriptErrorSentToBrowser="true"/>
        <rewrite>
            <rules>
                <clear />
                <rule name="Browser Error Rewrite" stopProcessing="true">
                    <match url="^errors/browser$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Rewrite" url="_errors/browser.php?error=browser" />
                </rule>
            </rules>
        </rewrite>
        <defaultDocument>
            <files>
                <clear />
                <add value="index.php" />
            </files>
        </defaultDocument>
        <httpErrors>
            <clear />
            <error statusCode="400" prefixLanguageFilePath="" path="/_errors/error.php?id=400" responseMode="ExecuteURL" />
            <error statusCode="502" prefixLanguageFilePath="" path="/_errors/error.php?id=502" responseMode="ExecuteURL" />
            <error statusCode="407" prefixLanguageFilePath="" path="/_errors/error.php?id=407" responseMode="ExecuteURL" />
            <error statusCode="414" prefixLanguageFilePath="" path="/_errors/error.php?id=414" responseMode="ExecuteURL" />
            <error statusCode="415" prefixLanguageFilePath="" path="/_errors/error.php?id=415" responseMode="ExecuteURL" />
            <error statusCode="501" prefixLanguageFilePath="" path="/_errors/error.php?id=501" responseMode="ExecuteURL" />
            <error statusCode="500" prefixLanguageFilePath="" path="/_errors/error.php?id=500" responseMode="ExecuteURL" />
            <error statusCode="401" prefixLanguageFilePath="" path="/_errors/error.php?id=401" responseMode="ExecuteURL" />
            <error statusCode="403" prefixLanguageFilePath="" path="/_errors/error.php?id=403" responseMode="ExecuteURL" />
            <error statusCode="404" prefixLanguageFilePath="" path="/_errors/error.php?id=404" responseMode="ExecuteURL" />
            <error statusCode="405" prefixLanguageFilePath="" path="/_errors/error.php?id=405" responseMode="ExecuteURL" />
            <error statusCode="412" prefixLanguageFilePath="" path="/_errors/error.php?id=412" responseMode="ExecuteURL" />
            <error statusCode="406" prefixLanguageFilePath="" path="/_errors/error.php?id=406" responseMode="ExecuteURL" />
        </httpErrors>
        <handlers>
            <clear />
            <add name="PageHandlerFactory-Integrated" path="*.aspx" verb="GET,HEAD,POST,DEBUG" type="System.Web.UI.PageHandlerFactory" preCondition="integratedMode" />
            <add name="php-5.3.10" path="*.php" verb="GET,HEAD,POST" modules="FastCgiModule" scriptProcessor="C:\Program Files (x86)\Parallels\Plesk\Additional\PleskPHP53\php-cgi.exe" resourceType="Either" requireAccess="Script" />
            <add name="StaticFile" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" />
        </handlers>
    </system.webServer>
</configuration>

Answer

Syed Salman Raza Zaidi picture Syed Salman Raza Zaidi · Jan 24, 2013

It seems that you have twice in your web.config (that's what the "Parser Error Message: Section or group name 'system.webServer' is already defined" error implies).

Search for in your application's web.config and cut the code in it and paste it to another one(make sure that code doesn't repeating) remove that one you have cut the code from