I am building AngularJs and WebApi application, usin Aspnet Core rc1. I have problem with returning static index.html
file. I have tried several methods. The first method was to use such code in Startup.cs
app.UseFileServer();
app.UseMvc();
In this way it works, if I call http://localhost:29838
(root url). But if I go on http://localhost:29838/books
( /books
root is my angular root defined using ng-route, and I am using html5 mode) and renew the page, server will return 404 mistake of course.
Then, I read this article https://dzone.com/articles/fixing-html5mode-and-angular .I have tried to use rewrite module method in web.config
/ Everything works fine. But I do not like this method. As I have understood it works only with IIS.
Finally, I have tried to use the first way, described in article (when Home/Index
returns html file).controller code is:
public ActionResult Index()
{
return File("~/index.html", "text/html");
}
and Startup.cs
is:
routes.MapRoute(
name: "Default",
url: "{*.}",
defaults: new
{
controller = "Home",
action = "Index",
}
);
Using this approach I have such erros: Refused to load the script 'http://localhost:29838/libs/jquery/dist/jquery.min.js' because it violates the following Content Security Policy directive: "script-src 'unsafe-inline'".
And I can not overcome this. What am I doing wrong?
app.UseStaticFiles();
/ andapp.UseDefaultFiles();