{"id":1782304,"date":"2021-01-09T15:47:58","date_gmt":"2021-01-09T20:47:58","guid":{"rendered":"https:\/\/www.codementor.io\/noorsaifi\/how-to-deploy-angular-asp-net-core-webapi-to-iis-on-shared-hosting-1dytrihj56"},"modified":"2021-01-09T15:47:58","modified_gmt":"2021-01-09T20:47:58","slug":"how-to-deploy-angular-asp-net-core-webapi-to-iis-on-shared-hosting","status":"publish","type":"station","link":"https:\/\/platodata.io\/plato-data\/how-to-deploy-angular-asp-net-core-webapi-to-iis-on-shared-hosting\/","title":{"rendered":"How to deploy Angular, ASP.NET Core WebAPI to IIS on Shared Hosting"},"content":{"rendered":"
So you have developed your Angular app with ASP.NET Core WebAPI and would like to deploy it to a Shared Windows hosting. Shared hosting provides budgeted plans are a great way to start your project with ready environment but comes with limited features.<\/p>\n
Your application is running smoothly on local environment, but to run it on a shared hosting account, I would suggest to consider the following steps :<\/p>\n
Folder Structure<\/strong> \/api\/<\/strong> \/app\/<\/strong> 1.1 Configure “environment\/environment.prod.ts”<\/strong> 1.2 Build Angular App<\/strong> 1.3 Add WEB.CONFIG file<\/strong> With the above files ready, we can xcopy the entire “dist” folder to “app” folder on shared hosting via FTP (FileZilla<\/a>).<\/p>\n Right click on ASP.NET Core WebAPI project in Visual Studio and click on Publish which brings the following screen. Configure the values as shown here: Click Next, and configure these settings. I am using .NET Core 5.0 version which is supported by my hosting provider. Check with your hosting provider for the supported .NET Core Versions. Click save to finish the settings. We are ready to publish our project and click on Publish button now. Visual Studio will generate the published files in the following folder:<\/p>\n Depending upon your hosting provider, you may have to change the hosting model in Web.Config file. By default it is configured as “inprocess”. Change hosting model to “OutOfProcess” as in the following:<\/p>\n Once all files are successfully published and Web.Config file is modified, navigate to the published folder and XCopy entire content to the API folder on your shared hosting account.<\/p>\n I would love to hear from you about these steps. If you find a better way, or have a suggestion, please do let me know.<\/p>\n Thanks<\/p>\n
To make the best use of limited features on a share hosting environment, my approach is to organize the project in the following folder structure:<\/p>\n<\/p>\n
api folder will contain the published WebAPI project.<\/p>\n
app folder will contain the build files of Angular application.<\/p>\n
Since we are going to host our WebAPI project in “\/api” folder, configure “environment.prod.ts” file as follows:<\/p>\nexport const environment = { production: true, apiUrl: '\/api'\n};\n<\/code><\/pre>\n
Angular.IO deployment guide<\/a> describes the build procedure in details. Following command prepares the required angular files for deployment in “dist” folder with base path configured to use “\/app\/” folder.<\/p>\nng build --prod --output-path dist --base-href \/app\/\n<\/code><\/pre>\n
Next would be to add the “web.config” file to angular app folder to configure iis rewrite rules.<\/p>\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<configuration> <system.webServer> <rewrite> <rules> <rule name=\"AngularJS Routes\" stopProcessing=\"true\"> <match url=\".*\" \/> <conditions logicalGrouping=\"MatchAll\"> <add input=\"{REQUEST_FILENAME}\" matchType=\"IsFile\" negate=\"true\" \/> <add input=\"{REQUEST_FILENAME}\" matchType=\"IsDirectory\" negate=\"true\" \/> <add input=\"{REQUEST_URI}\" pattern=\"^\/(api)\" negate=\"true\" \/> <\/conditions> <action type=\"Rewrite\" url=\"\/app\/\" \/> <\/rule> <\/rules> <\/rewrite> <\/system.webServer>\n<\/configuration>\n<\/code><\/pre>\n
<\/p>\n
<\/p>\n
<\/p>\n
\/bin\/Release\/publish\/\n<\/code><\/pre>\n
<\/p>\n
<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<configuration> <location path=\".\" inheritInChildApplications=\"false\"> <system.webServer> <handlers> <add name=\"aspNetCore\" path=\"*\" verb=\"*\" modules=\"AspNetCoreModuleV2\" resourceType=\"Unspecified\" \/> <\/handlers> <aspNetCore processPath=\".MyApp.WebAPI.exe\" stdoutLogEnabled=\"false\" stdoutLogFile=\".logsstdout\" hostingModel=\"OutOfProcess\" \/> <\/system.webServer> <\/location>\n<\/configuration>\n<\/code><\/pre>\n
\n
\n