locked
Visual Studio Resets Error Pages When Publishing a Web Application RRS feed

  • Question

  • User167985676 posted

    I have setup a very simple web application with a single maintenance page that will be used for a very big and complicated web site that has multiple pages and sub-folders and sub-sites etc. I setup the error elements in the web.config to point all to the Default.aspx page of the site and in order to handle someone attempting to get to an HTML page (MyPage.html) I have setup all of the entries for the Error Pages in IIS to point to this page as well.

    All of this works perfectly until I republish the maintenance web site, such as I would do when I make date and time changes to the outage page. Once I publish the website using Visual Studio it resets all of these error pages back to the default error pages.

    Is there away to keep Visual Studio from doing this?

    Using Visual Studio 2010 to manage the site
    Running IIS 7.5 on Windows Server 2008 R2 Enterprise

    Thanks
    Doug

    Monday, January 27, 2014 4:03 PM

Answers

  • User-1454326058 posted

    Hi dscarr,

    According to your description, I find you configured the customErrors section in the web.config file. In my opinion, it won’t affect the Error Pages setting in the IIS. That’s why it use the default IIS Error pages.

    As far as I know, all settings in the IIS will affect the system.webServer setting in the web.config file, such as default page, error page:

     <system.webServer>
            <defaultDocument>
                <files>
                    <add value="Test.html" />
                </files>
            </defaultDocument>
            <httpErrors>
                <error statusCode="407" path="/About.aspx" responseMode="ExecuteURL" />
            </httpErrors>
        
      </system.webServer>

    So, if you want specify the error page for the IIS, you should configure the system.webServer section.

    About more information about httpErrors, please refer to:

    # HTTP Errors <httpErrors>

    http://www.iis.net/configreference/system.webserver/httperrors

    There is a link that may benefit you:

    # What is the difference between customErrors and httpErrors

    http://stackoverflow.com/questions/2480006/what-is-the-difference-between-customerrors-and-httperrors

    Thanks

    Best Regards

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 29, 2014 9:51 PM

All replies

  • User-1454326058 posted

    Hi dscarr,

    According to your description, I tried it and it works fine. (The web.config didn’t be reset)

    Please provide the detail steps that you publish your project.

    On the other hand, please create a new project and try again.

    Thanks

    Best Regards  

    Tuesday, January 28, 2014 4:46 AM
  • User167985676 posted

    Starain . . .

    It's not the web.config thats getting reset, it's the IIS configuration. If you look at the site in IIS Manager and select the Error Pages under the IIS section it's these settings for each of the web errors (401, 403, 404, etc.) that I set to "/Default.aspx". After I publish the site (even though I have the "<error statusCode="401" redirect="/Default.aspx"/>" error elements in the <customErrors> section in the web.config file set for each of the corresponding errors) they get reset to the default IIS supplied pages ".

    I am publishing the site by clicking on the Build | Publish <site> menu option from Visual Studio. 

    I am using the File System publishing method

    I have the "Delete all existing files prior to publish" option chosen. Although I had the "Replace matching files with local copies" option chosen before and it made no difference.

    I have now setup the same site on two additional servers and I get the exact same result. Everytime I publish the site if wipes out my Error Page settings in IIS and puts them back to the default IIS supplied pages.

    When setting the pages in IIS I edit the entry for the error (404 for example) and select the "Execute a URL on this site" option and enter /Default.aspx"

    I tried using the first option "Insert content from static file into the error response" but this obviously won't work because an aspx file is not considered "static content" and it throws an error up to the calling page.

    Thanks,

    Doug

    Wednesday, January 29, 2014 8:25 AM
  • User-1454326058 posted

    Hi dscarr,

    According to your description, I find you configured the customErrors section in the web.config file. In my opinion, it won’t affect the Error Pages setting in the IIS. That’s why it use the default IIS Error pages.

    As far as I know, all settings in the IIS will affect the system.webServer setting in the web.config file, such as default page, error page:

     <system.webServer>
            <defaultDocument>
                <files>
                    <add value="Test.html" />
                </files>
            </defaultDocument>
            <httpErrors>
                <error statusCode="407" path="/About.aspx" responseMode="ExecuteURL" />
            </httpErrors>
        
      </system.webServer>

    So, if you want specify the error page for the IIS, you should configure the system.webServer section.

    About more information about httpErrors, please refer to:

    # HTTP Errors <httpErrors>

    http://www.iis.net/configreference/system.webserver/httperrors

    There is a link that may benefit you:

    # What is the difference between customErrors and httpErrors

    http://stackoverflow.com/questions/2480006/what-is-the-difference-between-customerrors-and-httperrors

    Thanks

    Best Regards

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 29, 2014 9:51 PM
  • User167985676 posted

    Starain . . .

    That was it. Thank you for the information. 

    Not sure how this got marked as the answer when I'm the one who asked the question and didn't mark it but it did solve the issue.

    I would also add that you need to add the clear element because not doing so causes IIS to throw an error when you attempt to look at the definition through IIS Manager.

        <httpErrors>
          <clear />
          <error statusCode="401" path="/Default.aspx" responseMode="ExecuteURL" />
          <error statusCode="403" path="/Default.aspx" responseMode="ExecuteURL" />
          <error statusCode="404" path="/Default.aspx" responseMode="ExecuteURL" />
          <error statusCode="405" path="/Default.aspx" responseMode="ExecuteURL" />
          <error statusCode="406" path="/Default.aspx" responseMode="ExecuteURL" />
          <error statusCode="412" path="/Default.aspx" responseMode="ExecuteURL" />
          <error statusCode="500" path="/Default.aspx" responseMode="ExecuteURL" />
          <error statusCode="501" path="/Default.aspx" responseMode="ExecuteURL" />
          <error statusCode="502" path="/Default.aspx" responseMode="ExecuteURL" />
        </httpErrors>



    Thanks again,

    Doug

    Tuesday, February 4, 2014 11:22 AM