gpt4 book ai didi

nancy - 自托管 Nancy 实例返回 404 错误

转载 作者:行者123 更新时间:2023-12-01 02:05:33 26 4
gpt4 key购买 nike

我正在尝试运行一个自托管的 Nancy 应用程序,但我无法让它返回有效响应。我是南希的新人;我希望我的问题是相当简单的。

这是一些代码:

class Program
{
static void Main(string[] args)
{
const String PORT_SETTING = "webServicePortNumber";
const String URI = "http://localhost:{0}/download/";

var portNum = ConfigurationManager.AppSettings[PORT_SETTING];
var uri = new Uri(String.Format(URI, portNum));

var config = new HostConfiguration {
UrlReservations = new UrlReservations { CreateAutomatically = true }
};

using (var nancyHost = new NancyHost(new Bootstrapper(), config, uri)) {
nancyHost.Start();

Console.WriteLine(String.Format("Listening on {0}. Press any key to stop.", uri.AbsoluteUri));
Console.ReadKey();
}

Console.WriteLine("Stopped. Press any key to exit.");
Console.ReadKey();
}
}

internal class Bootstrapper : DefaultNancyBootstrapper
{
protected override Nancy.Diagnostics.DiagnosticsConfiguration DiagnosticsConfiguration
{
get {
return new DiagnosticsConfiguration {
Password = @"[password]"
};
}
}
}

我的 NancyModule 看起来像这样:
public class DownloadsModule : NancyModule
{

public DownloadsModule() : base("/download")
{
RegisterRoutes();
}

private void RegisterRoutes()
{
Put["/"] = parms => InitiateDownload(parms);
Get["/"] = parms => Summary(parms);
Get["/{id}"] = parms => GetStatus(parms.requestId);
}

private Response GetStatus(Guid requestId)
{
return Response.AsText("TEST: GetStatus requestId " + requestId);
}

private Response Summary(dynamic parms)
{
return Response.AsText("Summary: You loved me before, do you love me now?");
}

private Response InitiateDownload(dynamic parms)
{
return Response.AsText("InitiateDownload.");
}
}

南希正在运行;我可以通过 http://127.0.0.1:8880/download/_Nancy/ 访问诊断信息.看着他们,路线似乎准备好了。交互式诊断/GetAllRoutes 显示:
P U T
name: [nothing] path: /download
G E T
name: [nothing] path: /download
name: [nothing] path: /download/{id}

然而,当我尝试 http://localhost:8880/download/ 时,我得到了 404。 .

诊断页面上的请求跟踪显示:
Method: GET
Request Url:
Scheme: http
Host Name: localhost
Port: 8880
Base Path: /download
Path: /
Query:
Site Base: http://localhost:8880
Is Secure: false
Request Content Type:
Response Content Type: text/html
Request Headers:
<snip>
Accept: text/html;q=1
application/xhtml+xml;q=1
image/webp;q=1
application/xml;q=0.9
*/*;q=0.8
<snip>
Response Headers:
Status Code: 404
Log: New Request Started
[DefaultResponseNegotiator] Processing as real response

那么为什么 Nancy 不将此请求路由到正确的路由呢?

最佳答案

jchannon 在 Nancy JabbR 房间向我指出的问题:

URI 指定 http://localhost:{0}/download/ ,而该模块还指定了 /download 的基本路径,所以目前它正在寻找 http://localhost:{0}/download/download/ 的 URL

关于nancy - 自托管 Nancy 实例返回 404 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32888814/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com