Change root in angular with asp.net core application
Change root in angular with asp.net core application
I want to change root in my application from angular-cli.json
or startup.cs
, when I debug the home page always is index.html
in folder " wwwroot ".
I'am using .net core 1.1.
angular-cli.json
startup.cs
index.html
This is my code in angular-cli.json
:
angular-cli.json
"apps": [
"root": "src",
"outDir": "wwwroot",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"styles.css"
],
"scripts": ,
"environmentSource": "environments/environment.ts",
"environments":
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
What would be the problem?
1 Answer
1
Try and use the following:
startup.cs
:
startup.cs
public void ConfigureServices(IServiceCollection services)
services.AddMvc();
// In production, the Angular files will be served from this directory
services.AddSpaStaticFiles(configuration =>
configuration.RootPath = "your/folder/path";
);
description:
Gets or sets the path, relative to the application root, of the
directory in which the physical files are located.
If the specified directory does not exist, then the
Microsoft.Extensions.DependencyInjection.SpaStaticFilesExtensions.UseSpaStaticFiles(Microsoft.AspNetCore.Builder.IApplicationBuilder)
middleware will not serve any static files
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
I did that but there is an exception " iservicecollection does not contain a definition for addspastaticfiles ",so i have installed " Install-Package Microsoft.AspNetCore.SpaServices -Version 1.1.1 " and put using ... in the top of startup.cs file , also i have .csproj file two packages ( <PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="1.1.1" /> <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" /> ) but the same exception appear !!
– mecab95
Sep 13 '18 at 15:26