{"id":644,"date":"2023-07-28T06:55:07","date_gmt":"2023-07-28T06:55:07","guid":{"rendered":"https:\/\/blog.hostinger.io\/support\/2023\/07\/28\/8184984-how-to-launch-an-asp-net-application-at-hostinger\/"},"modified":"2026-03-16T12:12:02","modified_gmt":"2026-03-16T12:12:02","slug":"8184984-how-to-launch-an-asp-net-application-at-hostinger","status":"publish","type":"post","link":"https:\/\/www.hostinger.com\/support\/8184984-how-to-launch-an-asp-net-application-at-hostinger\/","title":{"rendered":"How to Launch an ASP.NET Application at Hostinger"},"content":{"rendered":"<p class=\"no-margin\"><b><a href=\"https:\/\/dotnet.microsoft.com\/en-us\/apps\/aspnet\" target=\"_blank\" class=\"intercom-content-link\" rel=\"noopener\">ASP.NET<\/a><\/b> is a popular web development framework created by <b>Microsoft<\/b>. It allows developers to build dynamic and robust web applications, websites, and services using various programming languages like <b>C#<\/b> and<b> Visual Basic .NET<\/b>. <\/p><p class=\"no-margin\">\n<\/p><p class=\"no-margin\">With its powerful features and seamless integration with other Microsoft technologies, <b>ASP.NET simplifies the process of creating and deploying web applications<\/b>.<\/p><p class=\"no-margin\">\n<\/p><p class=\"no-margin\">The ASP.NET supported on Ubuntu is ASP.NET<b> core<\/b>. If you use ASP.NET MVC with<b> .NET Framework<\/b> or <b>Web API<\/b>, you might need to <b><a href=\"https:\/\/learn.microsoft.com\/en-us\/aspnet\/core\/migration\/mvc?view=aspnetcore-7.0\" target=\"_blank\" class=\"intercom-content-link\" rel=\"noopener\">convert your project to ASP.NET Core MVC<\/a><\/b> before you can deploy it in our Linux VPS.<\/p><p class=\"no-margin\">\n<\/p><p class=\"no-margin\">To launch the ASP.NET application at Hostinger, you need a <b>VPS<\/b> with <b><a href=\"\/support\/1583571-what-are-the-available-operating-systems-for-vps#h_ea21916da6\" target=\"_blank\" class=\"intercom-content-link\">Ubuntu 22.04 64bit with ASP.NET template<\/a><\/b> installed.<\/p><p class=\"no-margin\">\n<\/p><div class=\"intercom-interblocks-callout\" style=\"background-color: #e3e7fa80;border-color: #334bfa33\">\n<p class=\"no-margin\">Visit our <b><a href=\"https:\/\/www.hostinger.com\/vps\/asp-net-hosting\" target=\"_blank\" class=\"intercom-content-link\">ASP.NET hosting<\/a><\/b> page to learn more about the VPS plans available &#128640; <\/p>\n<\/div><p class=\"no-margin\">\n<\/p><h2 id=\"h_4767fec332\">Configure the ASP.NET Core Application<\/h2><p class=\"no-margin\">Once you <b><a href=\"\/support\/5723772-how-to-connect-to-your-vps-via-ssh\" target=\"_blank\" class=\"intercom-content-link\">log into your VPS via SSH<\/a><\/b>, you can check installed .NET versions by running this command:<\/p><pre><code>dotnet --version<\/code><\/pre><p class=\"no-margin\">To start off, we will create a simple web application from preinstalled templates and call it <b>NewApp<\/b>:<\/p><pre><code>dotnet new webapp -o NewApp<\/code><\/pre><p class=\"no-margin\">This creates a new folder for your application: <b>\/root\/NewApp\/<\/b>. Let&rsquo;s change the default port of your application to <b>5000<\/b> in <b>launchSettings.json<\/b>:<\/p><pre><code>nano \/root\/NewApp\/Properties\/launchSettings.json<\/code><\/pre><p class=\"no-margin\">It should look like this:<\/p><pre><code>  \"profiles\": {<br>    \"NewApp\": {<br>      \"commandName\": \"Project\",<br>      \"dotnetRunMessages\": true,<br>      \"launchBrowser\": true,<br>      \"applicationUrl\": \"http:\/\/localhost:5000\",<br>      \"environmentVariables\": {<br>        \"ASPNETCORE_ENVIRONMENT\": \"Development\"<br>      }<br>    }<\/code><\/pre><p class=\"no-margin\">Also, we have to remove the <b>UseHttpsRedirection()<\/b> middleware because we&rsquo;ll use NGINX to handle the HTTPS redirection. Open the <b>Program.cs<\/b> file and make sure there are no <b>app.UseHttpsRedirection()<\/b>:<\/p><pre><code> nano \/root\/NewApp\/Program.cs<\/code><\/pre><p class=\"no-margin\">We can add <b>app.UseForwardedHeaders()<\/b> middleware as well since we are using NGINX as a reverse proxy. It should look like this:<\/p><pre><code>var builder = WebApplication.CreateBuilder(args);<br>\/\/ Add services to the container.<br>builder.Services.AddRazorPages();<br>var app = builder.Build();<br>\/\/ Configure the HTTP request pipeline.<br>if (!app.Environment.IsDevelopment())<br>{<br>    app.UseExceptionHandler(\"\/Error\");<br>    \/\/ The default HSTS value is 30 days. You may want to change this for production scenarios, see https:\/\/aka.ms\/aspnetcore-hsts.<br>    app.UseHsts();<br>}<br>app.UseStaticFiles();<br>app.UseForwardedHeaders();<br>app.UseRouting();<br>app.UseAuthorization();<br>app.MapRazorPages();<br>app.Run();<\/code><\/pre><p class=\"no-margin\">\n<\/p><h2 id=\"h_b8e441012d\">Publish and Run the Application<\/h2><p class=\"no-margin\">To publish the application using the <b>Release<\/b> configuration, make sure you&rsquo;re in the <b>project directory<\/b>, and then run the command below:<\/p><pre><code>cd \/root\/NewApp\/<br>dotnet publish --configuration Release <\/code><\/pre><p class=\"no-margin\">The project has been published. Now, we must create a service to ensure the application starts and runs. First, let&rsquo;s <b>create a service file for<\/b> our project inside the <b>\/etc\/systemd\/system <\/b>directory:<\/p><pre><code>cd \/etc\/systemd\/system<br>sudo nano NewApp.service<\/code><\/pre><p class=\"no-margin\">In the new file, put the following configuration:<\/p><pre><code>[Unit]<br>Description=NewApp<br> <br>[Service]<br>WorkingDirectory=\/root\/NewApp\/bin\/Release\/net6.0\/publish\/<br>ExecStart=\/usr\/bin\/dotnet \/root\/NewApp\/bin\/Release\/net6.0\/publish\/NewApp.dll<br>Restart=always<br># Restart service after 10 seconds if the dotnet service crashes:<br>RestartSec=10<br>KillSignal=SIGINT<br>SyslogIdentifier=dotnet-NewApp<br>User=root<br>Environment=ASPNETCORE_ENVIRONMENT=Production<br>Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false<br> <br>[Install]<br>WantedBy=multi-user.target<\/code><\/pre><p class=\"no-margin\">Now, let&rsquo;s <b>enable and start the service<\/b> using the commands below:<\/p><pre><code>sudo systemctl enable NewApp.service<br>sudo systemctl start NewApp.service<\/code><\/pre><p class=\"no-margin\">\n<\/p><h2 id=\"h_7deebf0a21\">Install and Configure the NGINX<\/h2><p class=\"no-margin\">Start with <b>installing the NGINX server<\/b>. It is a popular open-source web server software known for its high performance, scalability, and robustness. It is widely used as a reverse proxy server, load balancer, and HTTP cache.<\/p><pre><code>sudo apt-get -y install nginx certbot python3-certbot-nginx<\/code><\/pre><p class=\"no-margin\">After the installation is completed, let&rsquo;s <b>configure the NGINX<\/b>. To do that, you can<b> edit the configuration file<\/b> using the command below:<\/p><pre><code>sudo nano \/etc\/nginx\/sites-available\/default <\/code><\/pre><p class=\"no-margin\">Let&rsquo;s make two changes to this file. First, set your domain name in <b>server_name<\/b>:<\/p><pre><code>server_name domain.tld; <\/code><\/pre><p class=\"no-margin\">Then, set the <b>location<\/b> configuration as follows:<\/p><pre><code>location \/ {<br>    proxy_pass http:\/\/localhost:5000;<br>    proxy_http_version 1.1;<br>    proxy_set_header Upgrade $http_upgrade;<br>    proxy_set_header Connection keep-alive;<br>    proxy_set_header Host $host;<br>    proxy_cache_bypass $http_upgrade;<br>    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br>    proxy_set_header X-Forwarded-Proto $scheme;<br>}<\/code><\/pre><p class=\"no-margin\">\n<\/p><h2 id=\"h_d34a73ab50\">Install an SSL and Launch the NGINX Proxy<\/h2><p class=\"no-margin\">Once the DNS propagation of your domain is completed, proceed with <b>generating the SSL certificate <\/b>for your ASP.NET application. Run the command below to generate the SSL certificate automatically:<\/p><pre><code>sudo certbot --nginx -d domain.tld<\/code><\/pre><p class=\"no-margin\">After that, <b>restart the NGINX<\/b> to apply the configuration:<\/p><pre><code>nginx -t &amp;&amp; nginx -s reload<\/code><\/pre><p class=\"no-margin\">Then, run the <b>crontab <\/b>command to <b>auto-renew the SSL certificate<\/b>:<\/p><pre><code>crontab -e<\/code><\/pre><p class=\"no-margin\">Finally, add the command below to <b>auto-renew the SSL every day at 12:00 (noon)<\/b>:<\/p><pre><code>0 12 * * * \/usr\/bin\/certbot renew --quiet<\/code><\/pre><p class=\"no-margin\">And that is it! You can now access your application via the domain you configured in this tutorial &#127881; <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Launching an ASP.NET application at Hostinger<\/p>\n","protected":false},"author":581,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"include_on_kodee":true,"footnotes":""},"categories":[199],"tags":[],"class_list":["post-644","post","type-post","status-publish","format-standard","hentry","category-vps-management"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/support\/8184984-how-to-launch-an-asp-net-application-at-hostinger\/","default":1}],"include_on_kodee":true,"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/posts\/644","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/users\/581"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/comments?post=644"}],"version-history":[{"count":0,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/posts\/644\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/media?parent=644"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/categories?post=644"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/tags?post=644"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}