我尝试在ApplicationStartup覆盖中的引导程序中添加它.
pipelines.AfterRequest.AddItemToStartOfPipeline(ctx => { ctx.Request.Headers["x-fcr-version"] = "1"; });
它给了我错误.
谁能指出我正确的方向?
解决方法
请注意在尝试操作响应时如何尝试设置请求?
试试这个..
protected override void RequestStartup(TinyIoCContainer container,IPipelines pipelines,NancyContext context) { base.RequestStartup(container,pipelines,context); pipelines.AfterRequest.AddItemToEndOfPipeline(c => { c.Response.Headers["x-fcr-version"] = "1"; }); }
这就是我的Response看起来像..
或者..如果要在模块级别设置它,可以使用Connection Negotiation …
Get["/"] = parameters => { return Negotiate .WithModel(new RatPack {FirstName = "Nancy "}) .WithMediarangeModel("text/html",new RatPack {FirstName = "Nancy fancy pants"}) .WithView("negotiatedview") .WithHeader("X-Custom","SomeValue"); };