Ich habe folgende Utilities.CS
Datei in meinem App_Code
Ordner als „Helfer“ Methoden in meiner MVC4 Anwendung (Build Aktion auf Kompilieren)‚Einstellungen‘ sind unzugänglich aufgrund seiner Schutzstufe
Es gibt einen Knickpunkt im Code wie angegeben ...
Die Anwendung kompiliert (Ctrl-Shift-B) ohne Fehler, aber wenn ich die Anwendung ausführen, bekomme ich eine CS0122: 'Settings' is inaccessible due to its protection level
bei der nachfolgenden return
Anweisung nach dem Break-Point.
Die AdminGroup
Einstellung wird als public
im Einstellungen-Designern definiert
Die Break-Punkt-Linie wird nie, wahrscheinlich aufgrund der Laufzeit Kompilierungsfehler getroffen ... aber wenn ich es kompiliert haben, warum ist es, Neu kompilieren zur Laufzeit?
(Sorry, ich bin neu auf MVC so nicht wirklich sicher, was los ist)
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));
}
}
}
}
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"]));
}
}
}
}
anzeigen Code für 'Properties'. Klicken Sie auf 'Eigenschaften' und drücken Sie' F12' –
Können Sie 'Eigenschaften' Klasse? – Kamo