NancyFX:路线与查询字符串参数总是返回一个404 NOTFOUND [英] NancyFX: Routes with query string parameters always returns a 404 NotFound

查看:484
本文介绍了NancyFX:路线与查询字符串参数总是返回一个404 NOTFOUND的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的南希模块。我想通过在查询字符串(QS)参数的处理程序。如果我没有任何QS PARAMS一切都很好。当我加入一个参数,然后我得到一个404状态code返回。

I have a simple Nancy module. I want to pass in query string (q-s) parameters to the handler. If I do not have any q-s params everything is fine. As soon as I add a param then I get a 404 status code returned.

NancyModule

public class SimpleModule : NancyModule
{
    public SimpleModule()
    {
        Get["/"] = parameters => HttpStatusCode.OK;
    }
}

单元测试 - 通过

[Fact]
public void SimpleModule__Should_return_statusOK_when_passing_query_params()
{
    const string uri = "/";
    var response = Fake.Browser().Get(uri, with => with.HttpRequest());
    response.StatusCode.ShouldBe(HttpStatusCode.OK);
}

单元测试 - 失败

[Fact]
public void SimpleModule__Should_return_statusOK_when_passing_query_params()
{
    const string uri = "/?id=1";
    var response = Fake.Browser().Get(uri, with => with.HttpRequest());
    response.StatusCode.ShouldBe(HttpStatusCode.OK);
}

感谢

推荐答案

您没有通过在URL中的查询,而不是使用.Query方法上的浏览器上下文

You don't pass in the query on the url, instead use the .Query method on the browser context

var result = browser.Get("/", with => {
    with.Query("key", "value");
});

这篇关于NancyFX:路线与查询字符串参数总是返回一个404 NOTFOUND的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆