- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想接受来自角度网站的选项请求。每个端点(注册、登录等)都需要接受选项 http 动词。
然后我会将以下内容添加到响应 header 中。
After += ctx =>
{
ctx.Response.WithHeader("Access-Control-Allow-Origin", "*");
ctx.Response.WithHeader("Access-Control-Allow-Headers", "accept, client-token, content-type");
ctx.Response.WithHeader("Access-Control-Allow-Methods", "POST, GET");
ctx.Response.WithHeader("Access-Control-Max-Age", "30758400");
};
我不想做的是为每个端点添加额外的路由
Post[path + "Login"] = x => Login();
Options[path + "Login"] = x => Login();
这将是大量样板代码。
有没有一种方法可以使用通配符路由拦截任何选项请求,以便我的所有端点都可以接受选项请求?
最佳答案
Nancy 对 OPTIONS
请求有隐式路由,即用户定义的 OPTIONS
路由尚未定义。参见 OptionsRoute
供引用。
如果你想为 OPTIONS
请求自定义行为,你可以选择添加一个 AfterRequest
钩子(Hook):
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
{
pipelines.AfterRequest += ctx =>
{
// This will always be called at the end of the request
if (ctx.Request.Method.Equals("OPTIONS", StringComparison.Ordinal))
{
ctx.Response.WithHeader("Access-Control-Allow-Origin", "*");
ctx.Response.WithHeader("Access-Control-Allow-Headers", "accept, client-token, content-type");
ctx.Response.WithHeader("Access-Control-Allow-Methods", "POST, GET");
ctx.Response.WithHeader("Access-Control-Max-Age", "30758400");
}
}
}
但我不太确定为什么您只将 CORS header 添加到 OPTIONS
响应中?
关于c# - 实现选项 HttpVerb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22068456/
我想接受来自角度网站的选项请求。每个端点(注册、登录等)都需要接受选项 http 动词。 然后我会将以下内容添加到响应 header 中。 After += ctx =>
我有一个具有以下操作的 Web API Controller : [HttpPut] public string Put(int id, JObject data) [Http
我正在尝试从另一个操作结果函数重定向到操作后结果。在这种情况下,我想从 Summary 函数重定向到 Index Post。那可能吗? 索引页是我的搜索页,Post 操作将返回结果。如果用户在地址栏中
我可以使用 [AcceptVerbs(HttpVerbs.Post)]/[AcceptVerbs(HttpVerbs.Get)] 来装饰操作 [AcceptVerbs(HttpVerbs.Post)]
当我尝试在 Java 中的移动浏览器上运行测试时。我收到以下错误 java.lang.NoClassDefFoundError: org/openqa/selenium/remote/HttpVerb
我正在使用 Hijaxing,我将有三个按钮:上一个、添加和下一个。劫持可与“添加”和“下一步”按钮一起使用。 上一个按钮设置为“onclick="history.back(-1)"”。 添加按钮由带
这些东西一样吗? [HttpPost/HttpGet] vs. [AcceptVerbs(HttpVerbs.Post/Get)] 如果不是,区别在哪里? 最佳答案 是的,完全一样。 [HttpPos
我是一名优秀的程序员,十分优秀!