ABP框架页面权限验证

.netcore

using System.Globalization;
using Abp.Application.Features;
using Abp.Authorization;
using Abp.Configuration;
using Abp.Extensions;
using Abp.Localization;
using Abp.Localization.Sources;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.AspNetCore.Mvc.Razor.Internal;

namespace Abp.AspNetCore.Mvc.Views
{
    /// 
    /// Base class for all views in Abp system.
    /// 
    /// Type of the View Model
    public abstract class AbpRazorPage : RazorPage
    {
        /// 
        /// Gets the root path of the application.
        /// 
        public string ApplicationPath
        {
            get
            {
                var appPath = Context.Request.PathBase.Value;
                if (appPath == null)
                {
                    return "/";
                }

                appPath = appPath.EnsureEndsWith('/');

                return appPath;
            }
        }

        /// 
        /// Reference to the localization manager.
        /// 
        [RazorInject]
        public ILocalizationManager LocalizationManager { get; set; }

        /// 
        /// Reference to the setting manager.
        /// 
        [RazorInject]
        public ISettingManager SettingManager { get; set; }

        /// 
        /// Reference to the permission checker.
        /// 
        [RazorInject]
        public IPermissionChecker PermissionChecker { get; set; }

        /// 
        /// Reference to the feature checker.
        /// 
        [RazorInject]
        public IFeatureChecker FeatureChecker { get; set; }

        /// 
        /// Gets/sets name of the localization source that is used in this controller.
        /// It must be set in order to use  and  methods.
        /// 
        protected string LocalizationSourceName
        {
            get { return _localizationSource.Name; }
            set { _localizationSource = LocalizationHelper.GetSource(value); }
        }
        private ILocalizationSource _localizationSource;

        /// 
        /// Constructor.
        /// 
        protected AbpRazorPage()
        {
            _localizationSource = NullLocalizationSource.Instance;
        }

        /// 
        /// Gets localized string for given key name and current language.
        /// 
        /// Key name
        /// Localized string
        protected virtual string L(string name)
        {
            return _localizationSource.GetString(name);
        }

        /// 
        /// Gets localized string for given key name and current language with formatting strings.
        /// 
        /// Key name
        /// Format arguments
        /// Localized string
        protected virtual string L(string name, params object[] args)
        {
            return _localizationSource.GetString(name, args);
        }

        /// 
        /// Gets localized string for given key name and specified culture information.
        /// 
        /// Key name
        /// culture information
        /// Localized string
        protected virtual string L(string name, CultureInfo culture)
        {
            return _localizationSource.GetString(name, culture);
        }

        /// 
        /// Gets localized string for given key name and current language with formatting strings.
        /// 
        /// Key name
        /// culture information
        /// Format arguments
        /// Localized string
        protected string L(string name, CultureInfo culture, params object[] args)
        {
            return _localizationSource.GetString(name, culture, args);
        }

        /// 
        /// Gets localized string from given source for given key name and current language.
        /// 
        /// Source name
        /// Key name
        /// Localized string
        protected virtual string Ls(string sourceName, string name)
        {
            return LocalizationManager.GetSource(sourceName).GetString(name);
        }

        /// 
        /// Gets localized string from given source  for given key name and current language with formatting strings.
        /// 
        /// Source name
        /// Key name
        /// Format arguments
        /// Localized string
        protected virtual string Ls(string sourceName, string name, params object[] args)
        {
            return LocalizationManager.GetSource(sourceName).GetString(name, args);
        }

        /// 
        /// Gets localized string from given source  for given key name and specified culture information.
        /// 
        /// Source name
        /// Key name
        /// culture information
        /// Localized string
        protected virtual string Ls(string sourceName, string name, CultureInfo culture)
        {
            return LocalizationManager.GetSource(sourceName).GetString(name, culture);
        }

        /// 
        /// Gets localized string from given source  for given key name and current language with formatting strings.
        /// 
        /// Source name
        /// Key name
        /// culture information
        /// Format arguments
        /// Localized string
        protected virtual string Ls(string sourceName, string name, CultureInfo culture, params object[] args)
        {
            return LocalizationManager.GetSource(sourceName).GetString(name, culture, args);
        }

        /// 
        /// Checks if current user is granted for a permission.
        /// 
        /// Name of the permission
        protected virtual bool IsGranted(string permissionName)
        {
            return PermissionChecker.IsGranted(permissionName);
        }

        /// 
        /// Determines whether is given feature enabled.
        /// 
        /// Name of the feature.
        /// True, if enabled; False if not.
        protected virtual bool IsFeatureEnabled(string featureName)
        {
            return FeatureChecker.IsEnabled(featureName);
        }

        /// 
        /// Gets current value of a feature.
        /// 
        /// Feature name
        /// Value of the feature
        protected virtual string GetFeatureValue(string featureName)
        {
            return FeatureChecker.GetValue(featureName);
        }
    }
}

.netmvc

using System.Globalization;
using System.Web;
using System.Web.Mvc;
using Abp.Application.Features;
using Abp.Authorization;
using Abp.Configuration;
using Abp.Dependency;
using Abp.Extensions;
using Abp.Localization;
using Abp.Localization.Sources;
using Abp.Web.Security.AntiForgery;

namespace Abp.Web.Mvc.Views
{
    /// 
    /// Base class for all views in Abp system.
    /// 
    /// Type of the View Model
    public abstract class AbpWebViewPage : WebViewPage
    {
        /// 
        /// Gets the root path of the application.
        /// 
        public string ApplicationPath
        {
            get
            {
                var appPath = HttpContext.Current.Request.ApplicationPath;
                if (appPath == null)
                {
                    return "/";
                }

                appPath = appPath.EnsureEndsWith('/');

                return appPath;
            }
        }

        /// 
        /// Reference to the setting manager.
        /// 
        public ISettingManager SettingManager { get; set; }
        
        /// 
        /// Gets/sets name of the localization source that is used in this controller.
        /// It must be set in order to use  and  methods.
        /// 
        protected string LocalizationSourceName
        {
            get { return _localizationSource.Name; }
            set { _localizationSource = LocalizationHelper.GetSource(value); }
        }
        private ILocalizationSource _localizationSource;

        /// 
        /// Constructor.
        /// 
        protected AbpWebViewPage()
        {
            _localizationSource = NullLocalizationSource.Instance;
            SettingManager = SingletonDependency.Instance;
        }

        /// 
        /// Gets localized string for given key name and current language.
        /// 
        /// Key name
        /// Localized string
        protected virtual string L(string name)
        {
            return _localizationSource.GetString(name);
        }

        /// 
        /// Gets localized string for given key name and current language with formatting strings.
        /// 
        /// Key name
        /// Format arguments
        /// Localized string
        protected virtual string L(string name, params object[] args)
        {
            return _localizationSource.GetString(name, args);
        }

        /// 
        /// Gets localized string for given key name and specified culture information.
        /// 
        /// Key name
        /// culture information
        /// Localized string
        protected virtual string L(string name, CultureInfo culture)
        {
            return _localizationSource.GetString(name, culture);
        }

        /// 
        /// Gets localized string for given key name and current language with formatting strings.
        /// 
        /// Key name
        /// culture information
        /// Format arguments
        /// Localized string
        protected string L(string name, CultureInfo culture, params object[] args)
        {
            return _localizationSource.GetString(name, culture, args);
        }

        /// 
        /// Gets localized string from given source for given key name and current language.
        /// 
        /// Source name
        /// Key name
        /// Localized string
        protected virtual string Ls(string sourceName, string name)
        {
            return LocalizationHelper.GetSource(sourceName).GetString(name);
        }

        /// 
        /// Gets localized string from given source  for given key name and current language with formatting strings.
        /// 
        /// Source name
        /// Key name
        /// Format arguments
        /// Localized string
        protected virtual string Ls(string sourceName, string name, params object[] args)
        {
            return LocalizationHelper.GetSource(sourceName).GetString(name, args);
        }

        /// 
        /// Gets localized string from given source  for given key name and specified culture information.
        /// 
        /// Source name
        /// Key name
        /// culture information
        /// Localized string
        protected virtual string Ls(string sourceName, string name, CultureInfo culture)
        {
            return LocalizationHelper.GetSource(sourceName).GetString(name, culture);
        }

        /// 
        /// Gets localized string from given source  for given key name and current language with formatting strings.
        /// 
        /// Source name
        /// Key name
        /// culture information
        /// Format arguments
        /// Localized string
        protected virtual string Ls(string sourceName, string name, CultureInfo culture, params object[] args)
        {
            return LocalizationHelper.GetSource(sourceName).GetString(name, culture, args);
        }

        /// 
        /// Checks if current user is granted for a permission.
        /// 
        /// Name of the permission
        protected virtual bool IsGranted(string permissionName)
        {
            return SingletonDependency.Instance.IsGranted(permissionName);
        }

        /// 
        /// Determines whether is given feature enabled.
        /// 
        /// Name of the feature.
        /// True, if enabled; False if not.
        protected virtual bool IsFeatureEnabled(string featureName)
        {
            return SingletonDependency.Instance.IsEnabled(featureName);
        }

        /// 
        /// Gets current value of a feature.
        /// 
        /// Feature name
        /// Value of the feature
        protected virtual string GetFeatureValue(string featureName)
        {
            return SingletonDependency.Instance.GetValue(featureName);
        }

        protected virtual void SetAntiForgeryCookie()
        {
            SingletonDependency.Instance.SetCookie(Context);
        }
    }
}

你可能感兴趣的:(ABP框架页面权限验证)