How to publish a .Net Web API in IIS Windows Server (http & https

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome everyone to it pro guide muhammad nia's with you in this video i'm going to show to you how you can run a web application in an is server running on a windows server so we are going to see how we can uh deploy a web application that you developed in a visual studio or you can develop it or you can download it even from the github link that i'm going to provide in the description so once you have a web application we can prepare a iis server then we can deploy it so we will test http how we can deploy and access it over http and also our https so for https we need a certificate so we will generate a self-signed ssl certificate and we will see how we can bind it and how we can make it working you can also do the same by purchasing a certificate but i prefer to do it in a self-signed certificate because if you're practicing this or if you are doing this for a development or a test environment then of course this is going to be the best choice because you don't need to pay for it until you go for the production so let's see how to do it i have logged in to my windows server the first step i'm going to do is to add the is role so this server is not joined to the domain if you want you can join to the domain controller but it's just a work group and the server name is web server so let's go to the manage and add the is roll into the server and for that complete the wizard the only job i need to do is during the server role option i have to select web server iis then click next and complete the wizard now the wizard has completed the installation so lets go to the iis and from there we can see internet information service manager so this is where the website configurations are you will see so if you expand the sites you can see there is a default website and simply click on the browse that will open the default website so this is the default website available uh in the is manager so this is how we can test our installation is correct or not so next i switch to a windows pc here i have a visual studio 2022 so what i'm going to do i'm going to create a web application here with the help of visual studio i'm not going to develop one here because there are so many templates available in visual studio so it's quite easy for me to generate one sample project from it so you can see i'm gonna select asp.net core web api so if you want any other project to try you can do it but this is going to be a web api application so i'm gonna select asp.net core web api then click next then give a meaningful name for the project if you don't want to download the visual studio and try this then you can see a link in the description that will take you to the github link you can simply download this from the github and you can also practice the same in your iis windows server so you can see the framework i'm going to choose is dotnet 6.0 so i have to install some supporting bundle for this application in the is server that we will take care in the next step so let's click on the create button that will create our template now a web api application is ready in visual studio we can just run this web api in the visual studio locally by clicking on the green button on the middle top uh it's web api is my application name that's why it's showing web api so it will open up with a swagger ui however we can test our uh web services so there will be urls and models on it those are uh for testing purpose so if you are a developer and you are making changes then you can develop your get post request at this uh swagger ui so i'm just uh testing uh trying to run uh some weather uh details so that is what this web api does so you can see that it is responding the response body have some responses so our aim is to deploy this web service of into an iis server so that it can be available or in the in the network then other people can use it and access it so we are going to see how we can do this so we are going to publish this web application this is what we do in visual studio when we complete the project or we want to test the project outside the visual studio we can publish it you can see there are different targets available we will go through one by one in the coming videos but in this video we are going to use a folder so point the folder location this is the default location which will create all the output in the same folder where the project is running so the final click on the publish will publish all the application files required to upload into the is server in the folder so you can open the folder here and these are the content for our web application now we need to take this to our iis server and we need to prepare our iis server to run this application so i switch to the iis server and i am going to paste the web of files that we copied so you can paste anywhere and find it but i'm pasting it in the right folder where the default web application was running so the files are now available in the iis server now the next step is to make this is server ready to run this application so you know that this application is a dotnet 6 application so we need to install a supporting bundle for hosting this application so that is what we are going to do next so search for a dot net core hosting bundle installer that will directly take you to the dotnet microsoft page and you can see that it is a dotnet six runtime windows hosting bundle installer so we need to install this in the is server then our web server will be ready to run our dotnet 6 web service application so now the iis server is ready let's go to the is manager and from there we are going to add our website for that click on the sites then from the sites you will see add website option then you have to give a site name i'm gonna give the same host name the host name of this server is a web server so i will give the same name then i need to point the physical part where the web application files it's in the www root file then i'm gonna choose http and i will change the port from h0 to 8080 because the default website in this machine is also using port 80 so it will give some error but it's okay i can change the default website port to something else and i can use port 80 but anyway this is how you can do it and the host name also i give now our web server it will be running in eight zero eight zero port in the iis server now the server is ready and running but our application is a web service actually it is not a a website so it will not give any information when you open simply the url so i'm going to make a get request so the default get request which comes with this template is uh you know the web server is the host name and eight zero zero is the port then slash weather forecast that will return the informations so now you can see uh the web service is running it's a web api application so the web service is running that is why we get this answer so http is okay http on port 8080 is okay the next step is to make this a secure web application by using https so let's see how to do this from the iis manager if you go to the web server page you will see server certificates and there you can create a self signed certificate so create a self-signed certificate give a meaningful name for the certificate this is just you to identify the certificate later then i prefer personal so this certificate will be stored in the personal folder that's it then click ok now we have a certificate ready now we need to bind this certificate to the our web application so let's go to the web server then you will see bindings then from the bindings it's running in the http so i'm not going to change anything here what i will do i will simply edit the binding and add a new binding so this site will be accessible in both http and https so keep all unassigned then port 443 then for the host name it's web server then down you will see ssl certificate there you have to select web server then click ok then close it now we have https ready so click https then full colon then run yeah because we don't need to use the port number 8080 so let's change it then let's try again now you can see that it is a secure we have a certificate and certificate is showing valid so this is a self-signed certificate so the self-signed certificate now it is showing valid because the certificate is available inside this system so if you want the client machines who are going to use this web service to show that this url is a trusted there is a certificate then you have to store those certificate manually to those pcs so let's see how to do that so to demonstrate you the access from a client pc i switched to a windows pc as you know our is server is a work group it is not joined to the domain so in order to resolve the web server that we prepared uh we need to add this web service ip address and domain name as a local entry in the host file so that is what i'm doing here so if you type web server from this pc as we already have the ip address in the local host file uh it will it will resolve it that's it now before you install the certificate if you try to access this server from other pc the url from other pc you will see that it show you a certificate warning because we have a ssl certificate but this certificate is not trusted by some of the trusted root certificates that have locally available in this pc like uh digi cert or any other uh certificate provider so what we need to do is we need to install this certificate inside this pc personal store so that next time when we browse the the browser will identify okay this certificate is available in my local store so i can trust it so let's see how to do that i have opened the same url in edge then when i click on the certificate error it pop up the certificate information where i can export to a file thereby i can save this a certificate then i want to install this certificate into my local pc certificate store for that just click on the install then open it then click select local machine then click next then place all the certificate in the following store then you can choose a trusted root certificate authorities then click ok then complete the wizard so next time when you try to browse this website it will show it will not show you any kind of certificate errors let's see so now you can see i'm gonna visit the same web server page uh from other pc where the certificate is installed and it is showing trusted because the certificate is available that's all thank you for watching this video and for more videos subscribe my youtube channel
Info
Channel: ITProGuide
Views: 31,775
Rating: undefined out of 5
Keywords:
Id: 79z8Ppqz1sA
Channel Id: undefined
Length: 13min 43sec (823 seconds)
Published: Wed Apr 13 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.