gpt4 book ai didi

ServiceStack 自托管站点默认页面

转载 作者:行者123 更新时间:2023-12-02 03:46:33 25 4
gpt4 key购买 nike

我已经尝试了所有自托管的 Razor 和 servicestack 模板,在这些项目中,如果安装了 razorFormat,则可以提供静态 html 和 cshtml。我不知道我做错了什么,我刚刚将代码复制到新的解决方案中,但我无法让 html 响应正常工作。我始终可以获得元数据页面并且服务正常工作。我无法添加 default.htm 并使其正常工作。
如果我输入 http://localhost:1337,我应该会被定向到默认页面。也许我错过了什么,但我不知道它是什么。如果有人能帮助我,我将不胜感激!

这是我的default.htm

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
SOMETEXT
</body>
</html>

这是我的程序

class Program
{
[Route("/hello")]
[Route("/hello/{Name}")]
public class Hello
{
public string Name { get; set; }
}

public class HelloResponse
{
public string Result { get; set; }
}

public class HelloService : Service
{
public object Any(Hello request)
{
return new HelloResponse { Result = "Hello, " + request.Name };
}
}

public class AppHost : AppHostHttpListenerBase {
public AppHost() : base("StarterTemplate HttpListener", typeof(HelloService).Assembly) {
}

public override void Configure(Funq.Container container) {
container.Register(new HelloService());
}
}

static void Main(string[] args)
{
var listeningOn = args.Length == 0 ? "http://*:1337/" : args[0];
var appHost = new AppHost();
appHost.Init();
appHost.Start(listeningOn);

Console.WriteLine("AppHost Created at {0}, listening on {1}", DateTime.Now, listeningOn);
Console.ReadKey();
}
}

编辑:我应该添加我得到的响应。

Handler for Request not found: 


Request.HttpMethod: GET
Request.HttpMethod: GET
Request.PathInfo: /default.htm
Request.QueryString:
Request.RawUrl: /default.htm

我尝试的另一件事是在 AppHostHttpListenerBase.Configure 中放置一个请求过滤器。我什至从未在我的项目中使用过它,但我在模板项目中使用过。

编辑:我发现问题是我的 Default.html 和 app.Config 文件没有移动到 bin/Debug 目录。有没有人遇到过这个问题?

最佳答案

Here is a good blog post关于为自托管/控制台应用程序提供 Razor 页面。我认为您不需要 app.config 或 web.config 文件,尽管我可能是错的。

我认为您缺少的两件事:

1) 将 Plugins.Add(new RazorFormat()) 添加到 AppHost 的 Configure 方法
2) 将 Razor 文件的“复制到输出目录”值更改为“如果更新则复制”(这在文件的属性设置中)。此外,将 default.htm 文件更改为 default.cshtml

关于ServiceStack 自托管站点默认页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16569252/

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