Workshop: Asp .NET Core para Iniciantes - Introdução

3 min read 4 months ago
Published on Aug 16, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

This tutorial is designed for beginners who want to learn the fundamentals of developing a simple application using ASP.NET Core. Through this step-by-step guide, you will gain a foundational understanding of this powerful framework and how to set up your first application.

Step 1: Setting Up Your Development Environment

Before you begin coding, ensure you have the necessary tools installed.

  • Install Visual Studio: Download and install the latest version of Visual Studio, which includes support for ASP.NET Core.
  • Install .NET SDK: Ensure you have the .NET SDK installed. You can download it from the official .NET website.
  • Verify Installation:
    • Open a command prompt and run the command:
      dotnet --version
      
    • This command should return the version number of the installed .NET SDK.

Step 2: Creating Your First ASP.NET Core Application

Now that your environment is set up, you can create your first application.

  • Open Visual Studio.
  • Create a New Project:
    • Select "Create a new project."
    • Choose "ASP.NET Core Web Application" and click "Next."
  • Configure Your Project:
    • Enter a project name and location.
    • Click "Create."
  • Select Project Template:
    • Choose the "Web Application" template (MVC) and click "Create."

Step 3: Understanding the Project Structure

Familiarize yourself with the structure of your new ASP.NET Core application.

  • Key Folders:
    • Controllers: Contains the logic for handling requests.
    • Views: Contains the HTML files and Razor views.
    • wwwroot: The root folder for static files (CSS, JS).

Step 4: Running Your Application

It's time to see your application in action.

  • Run the Application:
    • Click the green "Run" button in Visual Studio.
  • Access the Application:
    • Your default web browser should open, displaying your application at http://localhost:5000.

Step 5: Modifying the Application

Make simple modifications to personalize your application.

  • Edit the Home Controller:
    • Open Controllers/HomeController.cs.
    • Modify the Index action method to return a custom message:
      public IActionResult Index()
      {
          ViewData["Message"] = "Welcome to My ASP.NET Core Application!";
          return View();
      }
      
  • Update the View:
    • Open Views/Home/Index.cshtml.
    • Replace the content with:
      <h1>@ViewData["Message"]</h1>
      

Step 6: Exploring Additional Features

After mastering the basics, consider exploring these features to enhance your application.

  • Dependency Injection: Learn how to manage dependencies and services in your application.
  • Entity Framework: Explore how to interact with databases using Entity Framework Core.

Conclusion

You have now created a simple ASP.NET Core application and made initial modifications to it. This tutorial covered setting up your environment, creating a project, understanding its structure, running the application, and making basic changes.

For further learning, explore the official documentation and consider diving into advanced topics such as middleware, authentication, and deploying your application. You can also access the workshop repository for additional resources at GitHub Repository.