Tech Junkie Blog - Real World Tutorials, Happy Coding!: ACME Bank: Step 6: Running Your Asp.Net Core Application For The First Time

Thursday, July 8, 2021

ACME Bank: Step 6: Running Your Asp.Net Core Application For The First Time

Before we run our Asp.Net Core application for the first time we are going to copy a controller from Asp.Net Core 2.2 to help us create the skeleton for our application.  A skeleton are the plumbings we do at the beginning of our application to make sure all the mechanisms work.  It's called the ValuesController which has been replaced with a more complicated WeatherForecastController.  The ValuesController is just a lot easier to work with to get things set up.


Just create a new controller in the "Controllers" and call it "ValuesController.cs" Here is the code for it.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace ACMEBank.API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ValuesController : ControllerBase
    {
        // GET api/values
        [HttpGet]
        public ActionResult> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET api/values/5
        [HttpGet("{id}")]
        public ActionResult Get(int id)
        {
            return "value";
        }

        // POST api/values
        [HttpPost]
        public void Post([FromBody] string value)
        {
        }

        // PUT api/values/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody] string value)
        {
        }

        // DELETE api/values/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {
        }
    }
}

As you can see it's pretty basic.

Before we run our application for the first time we want to comment out the redirect https and keep our application in http mode in the beginning so that it's easier to work with. We also need to remove the https port in the launchSettings.json file, in Properties/launchSettings.json

Here is where you comment out the https redirect in the Startup.cs file

       // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

        {

            if (env.IsDevelopment())

            {

                app.UseDeveloperExceptionPage();

            }



            // app.UseHttpsRedirection();



            app.UseRouting();



            app.UseAuthorization();



            app.UseEndpoints(endpoints =>

            {

                endpoints.MapControllers();

            });

        }

Here is the change in launchSettings.json, make sure you remove the https: portion of the URL in the last configuration and just leave the http://localhost:5000

    "ACMEBank.API": {

      "commandName": "Project",

      "launchBrowser": true,

      "launchUrl": "weatherforecast",

      "applicationUrl": "http://localhost:5000",

      "environmentVariables": {

        "ASPNETCORE_ENVIRONMENT": "Development"

      }

Now you are ready to run the Asp.Net Core api by openning a terminal session and type dotnet run

Just open up the browser and browse to http://localhost:5000/api/values we would get the values from our HttpGet method of the ValuesController








Congratulation! You've just created your first API!

Previous: ACME Bank: Step 5: Setup Visual Code For C# Development With Extensions

Next: Add A Dev User In MySQL

9 comments:

  1. Your blog is very informative, finally, I found exactly what I want. Paypal is an excellent service for online payments but lots of its users confront issues while they access Paypal. If you want to resolve your problems then must visit Paypal contact Nederland.

    ReplyDelete
  2. Your blog is very informative and interesting to read, finally, I found exactly what I searching for. There are lots of users of Macfee antivirus in the world because of its features and easy interface. If you want to explore more interesting facts about Mcafee antivirus or want to resolve your technical issues then must visit Mcafee klantenservice nummer.

    ReplyDelete
  3. We’re a leader in electrical, lighting, and sign installation, manufacturing and repair services for commercial and industrial marketplace to address all your electrical needs. Visit our website to learn more!

    ReplyDelete
  4. Studio by TCS showcases carefully curated collections from an array of Pakistani designers and brings the best of Pakistani fashion to your doorstep. With the unparalleled strength and reliability of TCS’s logistics platform, Studio by TCS provides a seamless customer experience. We serve you with the same unflinching commitment to quality and customer service that has set TCS apart as a market leader for 34 years. With an eye on the future, Studio by TCS defines fashion in the digital age. Join us as we take Pakistani fashion global.

    ReplyDelete
  5. They can disrobe before you. If you need to recruit them for joy by blending with prominent Call Girls in Chanakyapuri, you can appreciate the night with a solitary call or WhatsApp message. On the off chance that you are frugal yet need to appreciate pleasurable closeness proceed to visit the spot while our agency furnish you with respectable and proficient Call Girls in Chanakyapuri to excite your remain. Our escort agency, Chanakyapuri Call Girls have connections to Call Girls in Chanakyapuri with the most blazing, sizzling and enchanting highlights. At long last, we know about some deceitful demonstrations submitted by most Call Girls in Chanakyapuri. You are really supposed to go for Call Girls in Chanakyapuri if you really want to have the best escort. You will surely be astonished to explore their natural beauty and looks. The Call Girls in Chanakyapuri always thinks of their clients.

    ReplyDelete
  6. We have actual scenarios that cause your purpose to double or treble. An escort maidservant is your partner for every action you want to do with them, similar to the Escorts Service in Chanakyapuri do. For your convenience, Eager for any of this young lady’s room, then you will be meeting with an independent, and clever young Escorts Service in Chanakyapuri committed to suit you an incredible social and suggestive experienceThe availability of Top Escorts Service in Chanakyapuri and other forms of Escorts, such as those associated with VIPs, makes it a popular choice amongst those who cannot afford their companion. Escorts Service in Chanakyapuri For Booking of Escorts Service in Chanakyapuri Delhi. Each and every detail that I have narrated here about my bodily assets is fully authentic and reliable We attempt the best Prostitutes in Chanakyapuri to be capable it give you the best assistance from our Escorts Service in Chanakyapuri. We have each sort of the young lady that can give you harmony and body love when you will invest enough energy with that young lady. But at the end of the day, human behavior is unpredictable and often goes against the tenets of probity and established norms. In this article, we will be delving a bit deep into the world of Escorts Service in Chanakyapuri

    ReplyDelete

Search This Blog