Line 32: ////authorization.Rules.Set(0, accessRule);
Line 33: ////configuration.Save(ConfigurationSaveMode.Minimal);
Line 34: "**This is the red marked erroneous line**"
Line 35:
Line 36: //StackTrace stackTrace = new StackTrace();
这是什么黑魔法?行中没有代码,甚至没有调用该行,但我得到的错误报告为:
当前web请求。请查看堆栈跟踪以了解更多信息
有关错误的信息及其在代码中的来源。
授权规则必须指定用户和/或角色的列表。
源文件:C:\MyProject\Accounts。aspx。cs线:34
然而,所有涉及授权的代码都被注释掉了,甚至没有调用该方法。方法:
public static void WriteAccsToAuth(List<User> allAllowedUsers)
{
//Configuration configuration = WebConfigurationManager.OpenWebConfiguration("~");
//AuthorizationSection authorization = (AuthorizationSection)configuration.GetSection("system.web/authorization");
//AuthorizationRule accessRule = new AuthorizationRule(AuthorizationRuleAction.Allow);
////foreach (User usr in allAllowedUsers)
////{
//// accessRule.Users.Add(usr.Domain + "\\" + usr.UserName);
////}
////Debug.WriteLine("Users count: " + accessRule.Users.Count);
////Debug.WriteLine("Rules count: " + authorization.Rules.Count);
////authorization.Rules.Set(0, accessRule);
////configuration.Save(ConfigurationSaveMode.Minimal);
"**This is the red marked erroneous line**"
//StackTrace stackTrace = new StackTrace();
//Debug.WriteLine("Users written to config file. Called by method " + stackTrace.GetFrame(1).GetMethod().Name + ".");
}
public static void LoadUsers()
{
...
//Accounts.WriteAccsToAuth(dbUsers.ToList());
...
}
我尝试过重建、重新启动Visual Studio和重新启动IIS。我的IIS是如何缓存错误的?我的意思是评论的行在错误消息中可见。。。我不知道这里发生了什么。