我尝试了所有自托管和servicestack的Razor模板,在这些项目中,如果安装了razorFormat,就可以提供静态html和cshtml。但我不知道哪里出了问题,我只是把代码复制到新的解决方案中,但无法让html响应起作用。我总能得到元数据页面并且服务也正常运行,但我无法添加default.htm并使其正常工作。
如果我输入http://localhost:1337,应该被重定向到默认页面。也许我错过了什么,但我不知道是什么。如果有人能帮帮我,我将非常感激!
这是我的default.htm。
这是我的程序。
这是我的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目录中。有人遇到过这个问题吗?
default.html
改为default.cshtml
。 - Jesse Webb