Chr*_*ond 6 c# asp.net-mvc class access-modifiers asp.net-mvc-4
我的Utilities.CS文件App_Code夹中有以下文件作为我的MVC4应用程序中使用的"帮助器"方法(构建操作设置为编译)
如图所示,代码中有一个断点......
应用程序编译(Ctrl-Shift-B)没有错误但是当我运行应用程序时,我在断点之后的CS0122: 'Settings' is inaccessible due to its protection level后续return语句中得到一个.
该AdminGroup设置public在"设置设计器"中定义
突破点一线从来没有被击中,可能是由于运行时编译错误......但如果我编译它,它为什么重新编译后在运行时?
(对不起,我是MVC的新手,所以不确定发生了什么)
namespace MyApplication
{
public class Utilities
{
public static string UserID
{
get
{
return Regex.Replace(WindowsIdentity.GetCurrent().Name, @".+\\", "").ToUpper();
}
}
public static bool IsAdmin
{
get
{
System.Diagnostics.Debug.WriteLine("Break point on this line");
return (HttpContext.Current.User.IsInRole(Properties.Settings.Default.AdminGroup));
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
UPDATE
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace MyApplication.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
//
// Other Settings Removed
//
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("MYDOMAIN\\ADMINGROUP")]
public string AdminGroup {
get {
return ((string)(this["AdminGroup"]));
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
Rah*_*ate 19
这个错误是因为Settings类是internal.
我假设您已经从visual studio项目属性部分设置中创建和修改了设置.Right click on project > Properties > Settings.有一个名为Access Modifier的下拉菜单,您需要将其从内部更改为公共.
有关internal关键字的更多信息: internal关键字是类型和类型成员的访问修饰符.内部类型或成员只能在同一程序集中的文件中访问
| 归档时间: |
|
| 查看次数: |
10990 次 |
| 最近记录: |