Category: Uncategorized

  • APIs

    ASP.NET Core provides frameworks for building APIs, gRPC services, and real-time apps with SignalR to instantly push data updates to clients.

    Basic Minimal API:

    C#Copy

    var builder = WebApplication.CreateBuilder(args);
    var app = builder.Build();
    
    app.MapGet("/hello", () => "Hello, World!");
    
    app.Run();
    

    With the previous code:

    • A minimal API is set up that listens for HTTP GET requests at the /hello URL and responds with “Hello, World!”.
    • The WebApplicationBuilder is used to configure the app.
    • The MapGet method defines a route and a handler for GET requests.

    Middleware

    ASP.NET Core uses a pipeline of middleware components to handle HTTP requests and responses. This modular approach provides flexibility, allowing you to customize and extend your application’s functionality by adding or removing middleware components as needed.

    The middleware pipeline processes HTTP requests in a sequential manner, ensuring that each component can perform its designated task before passing the request to the next component in the pipeline.

    Adding built-in middleware in the Program.cs file:

    C#Copy

    var builder = WebApplication.CreateBuilder(args);
    var app = builder.Build();
    
    app.UseHttpsRedirection();
    
    app.UseRouting();
    
    app.MapStaticAssets();
    
    app.UseAuthentication();
    
    app.UseAuthorization();
    
    app.MapGet("/", () => "Hello World!");
    
    app.Run();
    

    In the previous code, several common middleware components were added:

    • UseHttpsRedirection: Redirects HTTP requests to HTTPS.
    • UseRouting: Enables routing to map requests to endpoints.
    • MapStaticAssets: Optimizes the delivery of static files such as HTML, CSS, JavaScript, images and other assets.
    • UseAuthentication: Adds authentication capabilities.
    • UseAuthorization: Adds authorization capabilities.
    • app.MapGet: This is a simple endpoint to demonstrate that the application is running.
    networking training courses malaysia

  • How ASP.NET Core works

    An ASP.NET Core app is essentially a .NET app with a Program.cs file that sets up the web app component features you need and gets it running.

    The most basic ASP.NET Core app’s Program.cs file:

    C#Copy

    var builder = WebApplication.CreateBuilder(args);
    var app = builder.Build();
    
    app.MapGet("/", () => "Hello World!");
    
    app.Run();
    

    With the previous code:

    • A basic ASP.NET Core web application is set up that listens for HTTP GET requests at the root URL (“/”) and responds with “Hello World!”.
    • The app is initialized, configures a single route, and starts the web server.

    Blazor

    You can build interactive web UI with ASP.NET Core using Blazor. Blazor is a component-based web UI framework integrated with ASP.NET Core, used for building interactive web UIs using HTML, CSS, and C#.

    A reusable Blazor component, such as the following Counter component is defined in a Counter.razor file:

    razorCopy

    @page "/counter"
    @rendermode InteractiveServer
    
    <PageTitle>Counter</PageTitle>
    
    <h1>Counter</h1>
    
    <p role="status">Current count: @currentCount</p>
    
    <button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
    
    @code {
        private int currentCount = 0;
    
        private void IncrementCount()
        {
            currentCount++;
        }
    }
    

    With the previous code:

    • A component is created that displays a counter.
    • The @code block contains the component’s logic using C#, including a method to increment the counter.
    • The counter value is displayed and updated each time the button is clicked.
    • A component approach allows for code reuse across different parts of the application and has the flexibility to be run either in the browser or on the server in a Blazor app.

    The Counter component can be added to any web page in the app by adding the <Counter /> element.

    razorCopy

    @page "/"
    
    <PageTitle>Home</PageTitle>
    
    <h1>Hello, world!</h1>
    
    <Counter />
    it security training courses malaysia
  • What is ASP.NET Core?

    ASP.NET Core is a cross-platform, high-performance framework for building modern web applications. This open-source framework allows developers to create web applications, services, and APIs that can run on Windows, macOS, and Linux. It is built for large-scale app development and can handle any size workload, making it a robust choice for enterprise-level applications.

    Full stack web development

    ASP.NET Core is a full stack web framework that seamlessly integrates front-end and back-end development needs within a single consistent framework:

    • For front-end development, ASP.NET Core includes Blazor, a component-based web UI framework based on C# that supports both server-side rendering and client-side rendering via WebAssembly.
    • Alternatively, ASP.NET Core can be integrated with JavaScript front-end frameworks like Angular, React, and Vue.

    API development

    ASP.NET Core is a powerful framework for API development:

    • It supports creating JSON-based APIs, gRPC services, and real-time services using SignalR.
    • With built-in OpenAPI support, developers can easily generate and visualize API documentation, simplifying the design and consumption of APIs.
    • You can use ASP.NET Core to build back-end APIs for a variety of apps, including web apps and native mobile apps.
    software development training courses malaysia
  • When to use Blazor

    Blazor is a fully featured web UI framework designed to handle the needs of most modern web apps. But whether Blazor is the right framework for you depends on many factors.

    You should consider using Blazor for web development if:

    • You’re looking for a highly productive full stack web development solution.
    • You need to deliver web experiences quickly without the need for a separate frontend development team.
    • You’re already using .NET, and you want to apply your existing .NET skills and resources on the web.
    • You need a high-performance and highly scalable backend to power your web app.
    qa testing training courses malaysia
  • How Blazor works

    Blazor provides many features to help you get started and deliver your next web app project fast. Let’s take a tour of the core capabilities of Blazor to help you decide whether you should use Blazor for your next great web app.

    Blazor components

    Blazor apps are built from components. A Blazor component is a reusable piece of web UI. A Blazor component encapsulates both its rendering and UI event handling logic. Blazor includes various built-in components for form handling, user input validation, displaying large data sets, authentication, and authorization. Developers can also build and share their own custom components, and many prebuilt Blazor components are available from the Blazor ecosystem.

    Use standard web technologies

    You author Blazor components using Razor syntax, a convenient mixture of HTML, CSS, and C#. A Razor file contains plain HTML and then C# to define any rendering logic, like for conditionals, control flow, and expression evaluation. Razor files are then compiled into C# classes that encapsulate the component’s rendering logic. Because Blazor components authored in Razor are just C# classes, you can call arbitrary .NET code from your components.

    UI event handling and data binding

    Interactive Blazor components can handle standard web UI interactions using C# event handlers. Components can update their state in response to UI events and adjust their rendering accordingly. Blazor also includes support for two-way data binding to UI elements as a way to keep component state in sync with UI elements.

    The following example is a simple Blazor counter component implemented in Razor. Most of the content is HTML, while the @code block contains C#. Every time the button is pressed the IncrementCount C# method is invoked, which increments the currentCount field, and then the component renders the updated value:

    razorCopy

    <h1>Counter</h1>
    
    <p role="status">Current count: @currentCount</p>
    
    <button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
    
    @code {
        private int currentCount = 0;
    
        private void IncrementCount()
        {
            currentCount++;
        }
    }
    
    virtualization training courses malaysia
  • What is Blazor?

    Blazor is a modern frontend web framework based on HTML, CSS, and C# that helps you build web apps faster. With Blazor, you build web apps using reusable components that can be run from both the client and the server so that you can deliver great web experiences. Blazor is part of .NET, a developer platform for building anything. .NET is free, open-source, and runs cross-platform.

    aws certification malaysia
  • Understand tag helpers and page handlers

    In the previous unit, you created a Razor Page that displays a list of pizzas. You used the @ symbol to switch contexts between HTML and C#. In this unit, you’ll learn about tag helpers. Tag helpers are a special kind of HTML element that can contain C# code. You’ll also learn about page handlers. Page handlers are methods that handle browser requests. You’ll use page handlers in the next unit to add and delete pizzas.

    Tag helpers

    Tag helpers are used to address the inefficiencies of context switching between HTML and C#. Most of ASP.NET Core’s built-in Tag helpers extend standard HTML elements. Tag helpers provide extra server-side attributes for HTML elements, making the elements more robust.

    There are four tag helpers you should know for this project: Partial, Label, Input, and Validation Summary Message.

    Partial Tag Helper

    CSHTMLCopy

    <partial name="_ValidationScriptsPartial" />
    

    This injects the contents of the _ValidationScriptsPartial.cshtml file into a page. The _ValidationScriptsPartial.cshtml file contains JavaScript that’s used to validate form input, so it needs to be included on every page that contains a form.

    Label tag helper

    CSHTMLCopy

    <label asp-for="Foo.Id" class="control-label"></label>
    

    This extends the standard HTML <label> element. Like many tag helpers, it uses an asp-for attribute. The attribute accepts a property from the PageModel. In this case, the name of the PageModel‘s Foo.Id property (specifically, the string "Id") will be rendered as the content for an HTML <label> element.

    Input tag helper

    CSHTMLCopy

    <input asp-for="Foo.Id" class="form-control" />
    

    Similar to the previous example, this extends the standard HTML <input> element. It also uses an asp-for attribute to specify a PageModel property. In this case, the value of the Foo.Id property will be rendered as the value attribute for an HTML <input> element.

    Validation Summary Tag Helper

    CSHTMLCopy

    <div asp-validation-summary="All"></div>
    oracle certification malaysia

  • Handle events

    Blazor components often handle UI events. To specify an event callback for an event from a UI element, you use an attribute that starts with @on and ends with the event name. For example, you can specify the IncrementCount method as a handler for a button click event using the @onclick attribute, like this:

    razorCopy

    <button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
    

    You can specify C# event handlers for other HTML events too, like @onchange, @oninput, and so on. Event handling methods can be synchronous or asynchronous. You can also define event handlers inline using C# lambda expressions:

    razorCopy

    <button class="btn btn-primary" @onclick="() => currentCount++">Click me</button>
    

    Event handler methods can optionally take an event argument with information about the event. For example, you can access the value of an input element that changed, like this:

    razorCopy

    <input @onchange="InputChanged" />
    <p>@message</p>
    
    @code {
        string message = "";
    
        void InputChanged(ChangeEventArgs e)
        {
            message = (string)e.Value;
        }
    }
    

    After an event handler runs, Blazor will automatically render the component with its new state, so the message is displayed after the input changes.

    Data binding

    Often you want the value of a UI element to be bound to a particular value in code. When the value of the UI element changes, the code value should change, and when the code value changes the UI element should display the new value. Blazor’s data binding support makes it easy to set up this sort of two-way data binding.

    You bind a UI element to a particular value in code using the @bind attribute. For example:

    razorCopy

    <input @bind="text" />
    <button @onclick="() => text = string.Empty">Clear</button>
    <p>@text</p>
    
    @code {
        string text = "";
    }
    

    When you change the value of the input, the text field is updated with the new value. And when you change the value of the text field by clicking the Clear button, the value of the input is also cleared.

    red hat certification malaysia
  • Data binding and events

    Let’s explore how to define component rendering logic and handle UI events.

    Render C# expression values

    When you want to render the value of a C# expression in Razor, you use a leading @ character. For example, a Counter component can render the value of its currentCount field like this:

    razorCopy

    <p role="status">Current count: @currentCount</p>
    

    Razor can typically figure out when a C# expression ends and you transition back to writing HTML. But you can also be explicit about the beginning and ending of the expression using parens.

    razorCopy

    <p role="status">Current count: @(currentCount)</p>
    

    Add control flow

    You can add control flow to your component rendering logic using normal C# statements. For example, you can conditionally render some content using a C# if-statement, like this:

    razorCopy

    @if (currentCount > 3)
    {
        <p>You win!</p>
    }
    

    You can also use C# to loop over data and render a list of items:

    razorCopy

    <ul>
        @foreach (var item in items)
        {
            <li>@item.Name</li>
        }
    </ul>
    veeam certification malaysia
  • Razor components

    Now that you have your development environment set up, let’s explore the structure of a Blazor project and learn how Blazor components work.

    The Home page

    The app’s home page is defined by the Home.razor file located inside the Components/Pages directory. Home.razor contains the following code:

    razorCopy

    @page "/"
    
    <PageTitle>Home</PageTitle>
    
    <h1>Hello, world!</h1>
    
    Welcome to your new app.
    

    The @page directive at the top specifies the route for this page, so that the Home component is displayed when the user navigates to the root of the app. The PageTitle tag is a Blazor component that sets the title for the current page so that it shows up in the browser tab. The rest of the file is normal HTML that defines the content for the page.

    What is Razor?

    Razor is a markup syntax based on HTML and C#. A Razor file (.razor) contains plain HTML and then C# to define any rendering logic, like for conditionals, control flow, and expression evaluation. Razor files are then compiled into C# classes that encapsulate the component’s rendering logic.

    What are Razor components?

    If you explore the files in the Blazor project, you notice that most of the files that make up the project are .razor files. In Blazor, a Razor file defines a reusable component that makes up a portion of the app UI. Components define what HTML to render and how to handle user events.

    At compile time, each Razor component is built into a C# class. The class can include common UI elements like state, rendering logic, lifecycle methods, and event handlers. Because Blazor components authored in Razor are just C# classes, you can use arbitrary .NET code from your components.

    Using components

    To use a component from another component, you add an HTML-style tag with a name that matches the component name. For example, if you have a component named MyButton.razor, you can add a MyButton component to another component by adding a <MyButton /> tag.

    Component parameters

    Components can also have parameters, which allow you to pass data to the component when it’s used. Component parameters are defined by adding a public C# property to the component that also has a [Parameter] attribute. You can then specify a value for a component parameter using an HTML-style attribute that matches the property name. The value of the parameter can be any C# expression.

    The @code block

    The @code block in a Razor file is used to add C# class members (fields, properties, and methods) to a component. You can use the @code to keep track of component state, add component parameters, implement component lifecycle events, and define event handlers.

    lpi linux administration certification training courses malaysia