在我的web.config我有以下幾點:試圖從web.config中讀取 - 收到錯誤
<appSettings>
<add key="webpages:Enabled" value="false" />
<add key="authorizedUsers" value="jeff,jason,bob"/>
</appSettings>
在我_Layout.cshtml我有以下幾點:
@{
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>
}
}
當我運行這我得到Object reference not set to an instance of an object.
我需要做些什麼才能使這個工作?
不知道什麼是不對的或者你可以將列表從服務器端分配到''ViewBag.authList。 – Kaf