【c# – 从.Net Core 2.0中的IActionFilter获取HttpStatus代码】教程文章相关的互联网学习教程文章

C#:Bug,EndpointDispatcher&ContractFilter

项目发布的时候,文件上传忽然出现一个问题,很古怪,问题描述如下:Error:StackTrace: [FaultException:由于 ContractFilter在 EndpointDispatcher不匹配,因此Action为“http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue”的消息无法在接收方处理。这可能是由于协定不匹配(发送方和接收方Action 不匹配)或发送方和接收方绑定/安全不匹配。请检查发送方和接收方是否具有相同的协定和绑定(包括安全要求,如Message、Transpo...

c#-在IAuthenticationFilter的HttpAuthenticationContext中设置Cookie值【代码】

我需要在WebAPI管道的身份验证步骤中读取/写入cookie.我为此创建了一个自定义过滤器. 为了遵守自托管的概念,访问和向客户端写Cookie的安全方法是什么? Rick Strahl评论说,如果我们使用HttpContext.Current.Response.Cookies.Add(),并且我的应用程序是自托管的,则上下文可能/将不存在. 那么,如何使用HttpAuthenticationContext向客户端写一个cookie,并且仍然是自托管的呢?解决方法: HttpAuthenticationContext authContext; authC...

C#-HttpResponseException的抛出未被ExceptionFilterAttribute捕获【代码】

我有一堂课:public class ApiExceptionFilterAttribute : ExceptionFilterAttribute,IExceptionFilter { public override void OnException(HttpActionExecutedContext context){// ... etc...} }…因此我已经在global.asax.cs中注册:public class WebApiApplication : System.Web.HttpApplication {protected void Application_Start(){var exceptionFilter = new ApiExceptionFilterAttribute();GlobalConfiguration.Co...

如何在C#中解析OData $filter【代码】

操纵odata过滤器 如何操作后端中的过滤器并想要过滤查询参数的键值对? 表达式如下“?$filter =((Name eq ‘John’ or Name eq ‘Grace Paul’) and (Department eq ‘Finance and Accounting’))”由于有2个过滤器连接在一起.我怎样才能得到像这样的价值观Filter 1:Key: NameOperator: eqValue: NameOperator: orFilter 2:Key: NameOperator: eqValue: Grace PaulOperator: andFilter 3:Key: DepartmentOperator: eqValue: Financ...

c# – FileSystemWatcher.Filter – 缓冲区之前还是之后?

我正在开发一个项目,其中包含大量文件被修改和创建/删除.多个FSW内部缓冲区填充并且必须扩展时存在一些问题. 我在网上发现了有关“.Filter”是否在检测到的更改被添加到缓冲区之前过滤掉的信息.如果实际上在单个FSW之后进行事件排序可能会更有意义. 有谁知道这是确定的? 谢谢.解决方法:FileSystemWatcher包装本机W32方法ReadDirectoryChangesW,后者又负责将文件系统事件放入提供的缓冲区中.在事件已经在私有MatchPattern方法中缓冲...

c# – ServiceStack GetRequestFilterAttributes NullReference【代码】

我正在尝试使用ServiceStack的新API方法,我正在构建一个测试控制台应用程序来托管它.到目前为止,我有实例化请求DTO的路由,但在请求到达我的服务的Any方法之前,我得到了这个异常:Error Code NullReferenceException Message Object reference not set to an instance of an object. Stack Trace at ServiceStack.WebHost.Endpoints.Utils.FilterAttributeCache.GetRequestFilterAttributes(Type requestDtoType) at ServiceStac...

c# – WCF – AddressFilter不匹配【代码】

我有一个自托管的WCF服务,并在调用它时收到以下异常:The message with To ‘net.tcp://localhost:53724/Test1’ cannot beprocessed at the receiver, due to an AddressFilter mismatch at theEndpointDispatcher. Check that the sender and receiver’sEndpointAddresses agree.有效的解决方案是在服务接口的实现类之前添加[ServiceBehavior(AddressFilterMode = AddressFilterMode.Prefix)].但事实并非如此!所以,我试图找到...

c# – oData v4(6.1.0)在$expand中嵌套$filter【代码】

我有一个非常好用的asp.net 4.5 Web Api oData v4服务但是我今天遇到了一个问题,在$expand中有嵌套的$filters. 它说herethat OData V4 supports nested filters in $expand. The request belowreturn People and all their trips with Name “Trip in US”. GET serviceRoot/People?$expand=Trips($filter=Name eq ‘Trip in US’)它显示了一个很好的数据示例. Web API for oData v4 Docs here还有一个编码示例 我有这样的HTTP调用...

c# – 有没有办法创建一个ActionFilter,它在Action语句中包含Action的内容?【代码】

我的场景:我的应用程序是一个Web Api 2应用程序,它使用业务逻辑和存储库层进行数据访问. Web应用程序使用ASP.NET Impersonation以访问网站的用户身份登录数据库(通过PKI进行身份验证).我有几个异步控制器方法.但是,当我等待数据访问方法时,数据库调用可能会在另一个线程上完成,然后该线程将以我的应用程序池的标识访问数据库,该数据库不允许连接到数据库. 示例控制器:public class TestApiController : ApiController {private I...

c# – 在ExceptionFilter之前调用Controller.OnException吗?【代码】

试着在这里理解MVC管道: 似乎订单是这样的: > AuthorizationFilters> OnActionExecuting> ActionExecutes> OnActionExecuted> OnResultExecuting>创建操作结果> OnResultExecuted>写入响应流 Controller.OnException何时相对于ExceptionFilterAttribute.OnException运行?解决方法:它可能记录在某个地方,至少在源头,但我刚刚进行了这个小实验:// in MyHandleErrorAttribute, globally configured public override void OnExcept...

c# – 你可以在不全局的情况下注册Web API ActionFilter吗?【代码】

我已经看到如何在众多帖子中全局执行此操作并使其在我的代码中工作.问题是它在每次调用时触发这不是我想要的,我只希望它触发对我使用属性装饰方法的方法的调用:public class MyController : ApiController {[MyAttribute]public void MethodA(){// Do Work - should have called the attribute filter}public void MethodB(){// Do Work - should NOT have called the attribute filter} }这对我来说似乎是非常基本的,我错过了一些...

c# – 如何通过ASP.NET MVC View中的自定义Action Filter验证用户是否已通过身份验证?【代码】

我有一个使用我的身份验证过滤器的操作方法:public class TutorAuthenticationAttribute : ActionFilterAttribute {public override void OnActionExecuting(ActionExecutingContext filterContext){var req = filterContext.HttpContext.Request;var auth = req.Headers["Authorization"];if (!string.IsNullOrEmpty(auth)){var cred = System.Text.Encoding.ASCII.GetString(Convert.FromBase64String(auth.Substring(6))).Spli...

c# – 有没有办法将控制器的ModelState传递(或访问)到ActionFilterAttribute?【代码】

我有一个从动作过滤器属性派生的自定义验证属性.目前,该属性只是设置一个ActionParameter值,指示验证的项目是否良好,然后该操作必须具有逻辑来确定如何处理信息.public class SpecialValidatorAttribute: ActionFilterAttribute{public override void OnActionExecuting(ActionExecutingContext filterContext){// ... valdiation work done here ...filterContext.ActionParameters["SpecialIsValid"] = resultOfWork;base.OnActi...

c# – HttpModule,Response.Filter和未显示的图像【代码】

HttpModule工作正常(“hello”替换为“hello world”)但由于某些原因,当模块添加到Web.config时,WebForms上的图像不会显示.从Web.config中删除模块后,将显示WebForms上的图像. 有谁知道为什么? 使用或不使用HttpModule生成的HTML完全相同!//The HttpModulepublic class MyModule : IHttpModule {#region IHttpModule Memberspublic void Dispose(){//Empty}public void Init(HttpApplication context){context.BeginRequest += n...

c# – 从.Net Core 2.0中的IActionFilter获取HttpStatus代码【代码】

我在ASP.NET核心2.0中有过滤器属性,请参阅下面的我的代码片段.这里的问题是我总是得到状态码是200. 即使实际状态代码是500,那么我也得到200.如何获得实际状态代码?public void OnActionExecuted(ActionExecutedContext context) {try{var controller = context.Controller as APIServiceBase;var statusCode = controller.Response.StatusCode;....}catch { }}解决方法:这是一个有趣的问题.动作过滤器在动作本身之后执行.问题是该...

FILTER - 相关标签