Creating ASP.NET Core Web API with Swagger and Hosting within Virtual Directory in IIS

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi thanks for watching my video recently i hosted one web api application within a virtual directory in iis website the api application contained swagger documentation and the swagger ui was loaded with error like the current screen today i'm going to share how i fixed the problem if you've created web api application with swag already you can skip first bit and jump to 5 minutes let's get started first of all let's create a new web api application for the demo i'm using visual studio community 2019 i select asp.net core web api and name it my web api [Music] now my web api applications created the template contains web weather forecast controller and there is an example api to get a list of weather forecast let's run and see what we get from the api template as expected a list of weather forecast data is returned in json let's stop running and add swagger first of all we need to add swagger library open nougat package manager and search swag library select swashbuckle.asp.net and install now swagger package is installed and we'll need to add a few lines of code instead of file [Music] now let's run the application and see how flagger ui is looking like by default swagger ui parties slash swagger slash index.html the swagger ui is looking like this we can see available apis and requests and response details let's make a call for weather forecast api from the swagger click execute button and we can see the request url here also we can see 200 status code returned and the json data in the response body all good now let's host the api within a virtual directory i'm adding iis profile we can see app url which is within virtual directory my web api let's run it in iis we get fetch error let's check the error details in browser developer tool [Music] it's 404 not found error and the part is incorrect now let's go back to the to the code and fix the problem [Music] add virtual directory for server endpoint and add virtual directory app setting so we can change the value depending on the environment deployed [Music] finally we hosted api in the virtual directory my web api and the swagger ui has loaded successfully let's call the api and check the response api path is correct and the response looks good all done so the conclusion is add virtual directory when setting swagger endpoint thanks for watching hopefully this video was helpful
Info
Channel: Green Tiger
Views: 10,359
Rating: undefined out of 5
Keywords:
Id: mJNgCulJiak
Channel Id: undefined
Length: 8min 39sec (519 seconds)
Published: Sun Oct 03 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.