webdad3
webdad3

Reputation: 9090

Trying to read from web.config - getting error

In my web.config I have the following:

  <appSettings>
    <add key="webpages:Enabled" value="false" />
    <add key="authorizedUsers" value="jeff,jason,bob"/>
  </appSettings>

In my _Layout.cshtml I have the following:

@{
        List<String> authList = new List<string>();
        authList = System.Web.Configuration.WebConfigurationManager.AppSettings["authorizedUsers"].Split(',').ToList();

        if (authList.Any(u=>u == this.User.Identity.Name))
        {
            <li>@Html.ActionLink("Admin", "Index", "Admin")</li>
        }                               
}

When I run this I get Object reference not set to an instance of an object. What do I need to do to get this to work?

Upvotes: 0

Views: 1223

Answers (1)

ramsey_tm
ramsey_tm

Reputation: 792

My guess is you've put your setting in the wrong web.config. Double check you placed it in the appSettings section of the web.config located at project level and not the one located within the Views folder.

enter image description here

Upvotes: 3

Related Questions