首页 > 编程语言 >C# WebApi 权限过滤器

C# WebApi 权限过滤器

时间:2022-11-08 11:23:45浏览次数:33  
标签:WebApi filterContext C# 过滤器 new 权限 response

        protected override void HandleUnauthorizedRequest(HttpActionContext filterContext)
        {
            base.HandleUnauthorizedRequest(filterContext);

            var response = filterContext.Response = filterContext.Response ?? new HttpResponseMessage();
            response.StatusCode = HttpStatusCode.Forbidden;
            var content = new 
            {
                success = false,
                errs = new[] { "服务端拒绝访问:你没有权限,或者掉线了" }
            };
            response.Content = new StringContent(Json.Encode(content), Encoding.UTF8, "application/json");
        }

 

标签:WebApi,filterContext,C#,过滤器,new,权限,response
From: https://www.cnblogs.com/work-code/p/16869058.html

相关文章

  • Atcoder Beginner Contest 276(A~G)
    赛时A简单字符串处理;B简单vector处理;C找上一个排列。D找到每一个数因子\(2\)的个数和\(3\)的个数,并判断除去这些因子之后剩下的值是否相同,若不同则不能满足条......
  • 二叉搜索树 - C++ 实现
    二叉搜索树-C++实现......
  • shell编程 判断结构语句(if、case)
    一、if语句if语句通过关系运算符判断表达式的真假来决定执行哪个分支。Shell有三种if...else语句:if...fi语句;if...else...fi语句;if...elif...else......
  • nodejs Error: ENOENT: no such file or directory, open ‘input.txt‘
    nodejs运行下面代码:​​​报错:Error:ENOENT:nosuchfileordirectory,open'input.txt'解决:varfs=require("fs"); letpath=require('path');//引入p......
  • SpringBoot构建war部署到tomcat中无法注册到Nacos服务
    最近项目基本开发完成,准备部署到服务器中进行功能的验证,但当把所有的环境都搭建好,启动项目后,tomcat启动日志正常,发现在服务调用时一直报错。项目是使用SpringBoot框架搭建......
  • docker 安装jenkins
    1.dockerpulljenkins/jenkins 2.创建Jenkins挂载目录并授权权限(我们在服务器上先创建一个jenkins工作目录/var/jenkins_mount,赋予相应权限,稍后我们将jenkins容器目录......
  • HNCTF的pyjail做题过程详解
    简述:因为本人对python的内置函数理解也不是深入,在做题过程中也是靠着出题人的hint和google大法才做出来几题,详细的解题过程和知识点讲解可以看一下春哥的知乎,[PyJail]pyt......
  • 在线k8s练习环境,Killercoda和play-with-k8s
    最近发现了两款比较好的在线kubernetes操练环境,killercoda和play-with-k8s。尽管手头上已经有了ECS、虚拟机,不过这两款在线环境胜在方便快捷。让我们体验下吧!https://kill......
  • source insight 使用Uncrustify来格式化代码
    参考 ​​http://myswirl.blog.163.com/blog/static/5131864220106295590650/​​1.下载 ​​http://sourceforge.net/projects/uncrustify/​​,下载解压......
  • android 删除文件错误:open failed: EBUSY (Device or resource busy)
    引用:​​http://stackoverflow.com/questions/11539657/open-failed-ebusy-device-or-resource-busy​​IhavethebigAnswer!!TheProblemcomesfromtheAndroidSys......