NancyFX: Routes with query string parameters always returns a 404 NotFound

痴心易碎 提交于 2019-11-30 02:32:40

问题


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;
    }
}

Unit Test - Passes

[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);
}

Unit Test - Fails

[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);
}

Thanks


回答1:


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");
});


来源:https://stackoverflow.com/questions/10718763/nancyfx-routes-with-query-string-parameters-always-returns-a-404-notfound

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!