我正在使用OWIN来从Windows服务中通过http提供静态内容.(为Windows服务嵌入Web管理工具).
我经历了一些奇怪的行为:
顺便说一下,此"web"文件夹中的此文件被设置为"复制到输出目录"属性的"始终复制".
谁知道出了什么问题?
在这里看我的StartUp配置类
public class WebStartUp
{
public void Configuration(IAppBuilder app)
{
string staticFilesDir = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "web");
app.UseStaticFiles(staticFilesDir);
HttpConfiguration config = new HttpConfiguration();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
app.UseWebApi(config);
}
}
Run Code Online (Sandbox Code Playgroud)
在这里看到我托管它的Windows服务......
public partial class MyService : ServiceBase
{
private IDisposable webApp;
private const string ServiceAddress = "http://localhost:2345";
public MyService()
{
}
protected override void OnStart(string[] args)
{
InternalStart();
}
internal void InternalStart()
{
webApp = WebApp.Start<WebStartUp>(url: ServiceAddress);
}
protected override void OnStop()
{
}
public static void Main()
{
#if DEBUG
var service = new MyService();
Console.WriteLine("starting");
service.InternalStart();
Console.ReadLine();
#else
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[] {
new RaceManagerService();
}
ServiceBase.Run(ServicesToRun);
#endif
}
}
Run Code Online (Sandbox Code Playgroud)
我想我知道出了什么问题:您使用的第 3 方框架要么处于 alpha 要么处于 beta 状态。根据您对它们的经验以及它们的总体状态,您不应依赖它们。
我创建了一个几乎相同的设置(链接到项目文件)并看到了完全相同的结果。使用的库还不能胜任这项任务。
编辑:
我可以使用 Microsoft.Owin.StaticFiles 库的 0.23.20815.0 版本让它运行得更可靠。我根据最新的 Katana 资源自行构建了它。你可以在我的 GitHub 页面找到我的最新代码。