【发布时间】:2016-04-20 23:52:21
【问题描述】:
我的应用程序正在 Azure Service Fabric 中运行。在我的应用程序中,我使用 angularJS 作为前端的 asp.net web api。我的 web api 是带有 OWIN/Katana 的 self hostet,效果很好。
为了向客户端提供静态文件,我使用的是 OWIN 静态文件服务器。为了使用文件服务器,我从 Service Fabric 示例中进行了配置。
public void Configuration(IAppBuilder appBuilder)
{
HttpConfiguration httpConfig = this.ConfigureWebApi();
FileServerOptions fileServerOptions = this.ConfigureFileSystem(appBuilder);
appBuilder.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
appBuilder.UseWebApi(this.ConfigureWebApi());
appBuilder.UseFileServer(fileServerOptions);
}
private FileServerOptions ConfigureFileSystem(IAppBuilder appBuilder)
{
PhysicalFileSystem physicalFileSystem = new PhysicalFileSystem(@".\wwwroot");
FileServerOptions fileOptions = new FileServerOptions();
fileOptions.EnableDefaultFiles = true;
fileOptions.RequestPath = PathString.Empty;
fileOptions.FileSystem = physicalFileSystem;
fileOptions.DefaultFilesOptions.DefaultFileNames = new[] { "index.html" };
fileOptions.StaticFileOptions.FileSystem = fileOptions.FileSystem = physicalFileSystem;
fileOptions.StaticFileOptions.ServeUnknownFileTypes = true;
return fileOptions;
}
文件目录如下所示:
wwwroot
--+ app
----+ content
------+ css
-------- site.css
----+ bower_components
------+ angular
-------- angular.min.js
----- app.js
--- index.html
所有这些文件也在构建后的 bin/Debug/ 文件夹中。当我在浏览器中打开地址 http://localhost:80/ 时,我得到了 index.html 文件。但是除了http://localhost:80/app/app.js 之外的所有其他文件都找不到。
index.html 中的引用如下所示:
<link href="app/content/css/site.css" rel="stylesheet" />
<script src="app/bower_components/angular/angular.min.js"></script>
<script src="app/app.js"></script>
我尝试了很多其他配置,但都不起作用。有什么问题,我看不到吗?
【问题讨论】:
标签: angularjs asp.net-web-api owin self-hosting azure-service-fabric