Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8494595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:20:38+00:00 2026-06-10T23:20:38+00:00

I am trying to figure out why I am getting a NullReferenceException with the

  • 0

I am trying to figure out why I am getting a NullReferenceException with the following code. Everything seems to look like it is nested properly. I am using Microsoft.Web.Administration and I am attempting to modify the prefixLanguageFilePath for all the errors. Any help would be appreciated!

    public static void ModifyCustomErrDir(string dir)
    {
        try
        {
            ServerManager serverManager = new ServerManager();
            Configuration config = serverManager.GetApplicationHostConfiguration();

            config.GetSection("system.webServer/httpErrors").ChildElements["error"].Attributes["prefixLanguageFilePath"].Value = dir;
        }
        catch (ServerManagerException e)
        {
            Console.WriteLine(e);
        }
    }

    <httpErrors lockAttributes="allowAbsolutePathsWhenDelegated,defaultPath">
        <error statusCode="401" prefixLanguageFilePath="%SystemDrive%\inetpub\custerr" path="401.htm" />
        <error statusCode="403" prefixLanguageFilePath="%SystemDrive%\inetpub\custerr" path="403.htm" />
        <error statusCode="404" prefixLanguageFilePath="%SystemDrive%\inetpub\custerr" path="404.htm" />
        <error statusCode="405" prefixLanguageFilePath="%SystemDrive%\inetpub\custerr" path="405.htm" />
        <error statusCode="406" prefixLanguageFilePath="%SystemDrive%\inetpub\custerr" path="406.htm" />
        <error statusCode="412" prefixLanguageFilePath="%SystemDrive%\inetpub\custerr" path="412.htm" />
        <error statusCode="500" prefixLanguageFilePath="%SystemDrive%\inetpub\custerr" path="500.htm" />
        <error statusCode="501" prefixLanguageFilePath="%SystemDrive%\inetpub\custerr" path="501.htm" />
        <error statusCode="502" prefixLanguageFilePath="%SystemDrive%\inetpub\custerr" path="502.htm" />
    </httpErrors>

Edit:

I got it working by looping through the collection without denoting the error tag and just looking for the attribute. I will have to come back to it to see if there would be any unintended adverse “features” by doing it this way.

var httpErrorsCollection = config.GetSection("system.webServer/httpErrors")
       .GetCollection(); 

foreach (var error in httpErrorsCollection) 
    error.Attributes["prefixLanguageFilePath"].Value = dir;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T23:20:39+00:00Added an answer on June 10, 2026 at 11:20 pm
    //config.GetSection("system.webServer/httpErrors").ChildElements["error"].
    //        Attributes["prefixLanguageFilePath"].Value = dir;
    
    var errorSection = config.GetSection("system.webServer/httpErrors");
    // check errorSection    
    var errors = errorSection.ChildElements["error"];
    // check errors
    errors.Attributes["prefixLanguageFilePath"].Value = dir;
    

    etc

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out IO using StaX, but I keep getting malformed and
Trying to figure out how I can do this properly. The print_r looks like
I'm getting really tired of trying to figure out why this code works in
I'm trying to figure out why I'm getting the following exception when a client
I am trying to figure out why I am getting an error when using
I've been trying to figure out why this code is not getting hit. The
I'm trying to figure out why the Facebook Like comment box is getting cropped.
I'm trying to figure out what I'm doing wrong here. Using autocomplete I'm getting
I am trying to figure out why I am getting EXC_BAD_ACESS by this code.
I have been trying to figure out why I am getting this problem and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.