• webapi 设置帮助页面隐藏或显示


    1 设置口令 testV

    2 设置拦截器 

     public class CustomAuthorizeAttribute: AuthorizeAttribute
        {
            public override void OnAuthorization(AuthorizationContext filterContext)
            {
                //如果是在!testV条件下,则将一切请求(指的是应用了CustomAuthorize的控制器class或method)直接重定向到404页面;反之,执行默认行为
    #if !testV
                filterContext.Result = new RedirectResult("~/404.html");
    #endif
            }

        }

    3 将拦截器设置到帮助页面中

    ①在RegisterBundles中设定如下

     public static void RegisterBundles(BundleCollection bundles)
            {
    #if testV
                bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                            "~/Scripts/jquery-{version}.js"));

                // 使用要用于开发和学习的 Modernizr 的开发版本。然后,当你做好
                // 生产准备时,请使用 http://modernizr.com 上的生成工具来仅选择所需的测试。
                bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                            "~/Scripts/modernizr-*"));

                bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                          "~/Scripts/bootstrap.js",
                          "~/Scripts/respond.js"));

                bundles.Add(new StyleBundle("~/Content/css").Include(
                          "~/Content/bootstrap.css",
                          "~/Content/site.css"));
    #endif
            }

    ② 在HelpePage.controllers中设定拦截器

     ///


        /// The controller that will handle requests for the help page.
        ///

        [CustomAuthorizeAttribute]
        public class HelpController : Controller
        {
            private const string ErrorViewName = "Error";

            public HelpController()
                : this(GlobalConfiguration.Configuration)
            {
            }

  • 相关阅读:
    虚拟机中Linux下安装服务器
    Redis——zset类型详解
    大数据Flink(七十二):SQL窗口的概述和Over Windows
    JAVA基础——day07
    小Z的拼数游戏c++(求 解)
    R语言使用dev.print函数将当前最近的可视化结果保存为指定格式、dev.print函数不打开图像设备
    qsort库函数的使用
    thinkphp 项目报错No input file specified.
    关于后台列表,跳转详情和编辑页面
    ros2 -foxy安装cartographer建图定位-- 源码安装 使用
  • 原文地址:https://blog.csdn.net/qq_32733803/article/details/126164219