won*_*ate 7 .net angular .net-core-2.0
我的.Net Core API和我的Angular站点都在本地构建和运行.现在我想发布到.Net Hosting provier,而不是Azure.那么最好的方法是启用静态内容然后构建我的Angular应用程序并将其放在API解决方案的wwwroot中吗?
附注:我正在使用.net core 2.x,如果这很重要的话.并且,通过Angular我的意思是Angular2而不是AngularJS.这是标准术语吗?:-)
Bra*_*rad 12
要回答您的问题,是的,您应该启用静态内容并构建您的Angular应用和文件wwwroot.
这是最简单的Startup,可用于在.NET Core 2.0上提供Angular应用程序.
public class Startup
{
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// this will serve wwwroot/index.html when path is '/'
app.UseDefaultFiles();
// this will serve js, css, images etc.
app.UseStaticFiles();
// this ensures index.html is served for any requests with a path
// and prevents a 404 when the user refreshes the browser
app.Use(async (context, next) =>
{
if (context.Request.Path.HasValue && context.Request.Path.Value != "/")
{
context.Response.ContentType = "text/html";
await context.Response.SendFileAsync(
env.ContentRootFileProvider.GetFileInfo("wwwroot/index.html")
);
return;
}
await next();
});
}
}
Run Code Online (Sandbox Code Playgroud)
如您所见,不需要MVC或剃刀视图.
| 归档时间: |
|
| 查看次数: |
2017 次 |
| 最近记录: |