m.h.bayan
m.h.bayan

Reputation: 281

publish website used ASP mvc and angular 2

I use angular 2 to develop front end and use Asp MVC (not ASP CORE) for back end...

in normal asp mvc application use this steps to publish app :

  1. right click on project
  2. select publish on menu
  3. select profile name
  4. connection ...

and other steps

when I use that steps and upload my website on host website just show default loading message used in

"<my-app>Loading...</my-app>"

this is my published folder used by default steps :

published asp mvc & angular 2 web application folder and files

please help me ! and say me steps for publish my web application

tanks

Upvotes: 1

Views: 434

Answers (1)

maxs87
maxs87

Reputation: 2284

Well, i have faced this problem not long time ago, unfortunately i didnt found alot of information about it but can share some experience.

  1. create folder inside solution for build artifacts (wwwroot in my case)
  2. configure angular cli or whatever you use to build your project to store build artifacts there (in my case in .angular-cli.json file set "outDir": "PROJECT_PATH_OR_EMPTY_IF_ITS_IN_SAME_FOLDER/wwwroot")
  3. build angular app (in my case ng build --prod --output-hashing=none --environment=qa)

here the problems starts: In .net core you can just configure project to load index.html file from wwwroot folder and everything is fine, but i couldn`t do it in that case (any ideas apreciated)

So...

  1. modify default route for mvc app to load only one view (angular itself will take care afterwards)

    routes.MapRoute( name: "Default", url: "{*url}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } );

  2. modify layout page - copy all index.html content to _Layout.html (make sure that script tags refers to correct files in wwwroot folder)

  3. publish as usual

solution example

enter image description here

I hope it will help.

Upvotes: 2

Related Questions