Tôi có Utilities.CS
tập tin sau đây trong thư mục App_Code
của tôi là "helper" phương pháp sử dụng trong suốt ứng dụng MVC4 tôi (Build Action thiết để biên dịch)'Cài đặt' là không thể tiếp cận do mức độ bảo vệ của nó
Có một break-point trong mã như được chỉ định ...
Biên dịch ứng dụng (Ctrl-Shift-B) không có lỗi nhưng khi tôi chạy ứng dụng, tôi nhận được CS0122: 'Settings' is inaccessible due to its protection level
tại câu lệnh sau return
sau điểm ngắt.
Thiết lập AdminGroup
được định nghĩa là public
trong thiết kế Cài đặt
Các ngắt dòng điểm không bao giờ bị đánh, có thể là do thời gian chạy lỗi biên dịch ... nhưng nếu tôi đã biên soạn nó, tại sao nó lại tái biên dịch tại thời gian chạy?
(Xin lỗi, tôi mới để MVC vì vậy không thực sự chắc chắn những gì đang xảy ra)
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));
}
}
}
}
CẬP NHẬT
//------------------------------------------------------------------------------
// <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"]));
}
}
}
}
Hiện mã cho 'Properties'. Nhấp vào 'Properties' và nhấn 'F12' –
Bạn có thể lớp' Properties' không? – Kamo