Lab Session On Chapter 3
Lab Session On Chapter 3
Prerequisites
You need Visual Studio
Create a project
First, you'll create an ASP.NET Core project. The project type comes with all the template
files you'll need to build a fully functional website.
2. In the Create a new project window, select C# from the Language list. Next,
select Windows from the platform list, and Web from the project types list.
After you apply the language, platform, and project type filters, select the ASP.NET
Core Web App template, and then select Next.
Starting with C# & ASP.NET in Visual Studio- By Metekia Sada(BSc. In Software Engineering) Page 1
Starting with C# & ASP.NET in Visual Studio- By Metekia Sada(BSc. In Software Engineering) Page 2
3. In the Configure your new project window, enter MyCoreApp in the Project
name field. Then, select Next.
None. No authentication.
Individual accounts. These authentications are stored in a local or Azure-based
database.
Microsoft identity platform. This option uses Active Directory, Azure AD, or
Microsoft 365 for authentication.
Windows. Suitable for intranet applications.
Leave the Enable Docker box unchecked, and select None for Authentication Type.
Next, select Create.
Starting with C# & ASP.NET in Visual Studio- By Metekia Sada(BSc. In Software Engineering) Page 3
Visual Studio will open up your new project.
Starting with C# & ASP.NET in Visual Studio- By Metekia Sada(BSc. In Software Engineering) Page 4
2. Expand the Pages folder.
Starting with C# & ASP.NET in Visual Studio- By Metekia Sada(BSc. In Software Engineering) Page 5
3. Select the Index.cshtml file, and view in the code editor
4. Each .cshtml file has an associated code file. To open the code file in the editor,
expand the Index.cshtml node in Solution Explorer, and select
the Index.cshtml.cs file
Starting with C# & ASP.NET in Visual Studio- By Metekia Sada(BSc. In Software Engineering) Page 6
6. The project contains a wwwroot folder that is the root for your website. Expand
the folder to view its contents.
You can put static site content—such as CSS, images, and JavaScript libraries—
directly in the paths where you want them.
Starting with C# & ASP.NET in Visual Studio- By Metekia Sada(BSc. In Software Engineering) Page 7
7. The project also contains configuration files that manage the web app at run
time. The default application configuration is stored in appsettings.json.
However, you can override these settings by
using appsettings.Development.json. Expand the appsettings.json file to view
the appsettings.Development.json file
Starting with C# & ASP.NET in Visual Studio- By Metekia Sada(BSc. In Software Engineering) Page 8
2. Visual Studio launches a browser window. You should then
see Home and Privacy pages in the menu bar.
Starting with C# & ASP.NET in Visual Studio- By Metekia Sada(BSc. In Software Engineering) Page 9
3. Select Privacy from the menu bar. The Privacy page in the browser renders the
text that is set in the Privacy.cshtml file.
4. Return to Visual Studio, and then press Shift+F5 to stop debugging. This action
closes the project in the browser window.
5. In Visual Studio, open Privacy.cshtml for editing. Next, delete the sentence, Use
this page to detail your site's privacy policy and replace it with This page is under
construction as of @ViewData["TimeStamp"].
Mouseover or select a greyed out using directive. A Quick Actions light bulb will appear
just below the caret or in the left margin. Select the light bulb, and then select Remove
unnecessary usings
Starting with C# & ASP.NET in Visual Studio- By Metekia Sada(BSc. In Software Engineering) Page
10
Now select Preview changes to see what will change.
Select Apply. Visual Studio deletes the unnecessary using directives from the file.
Starting with C# & ASP.NET in Visual Studio- By Metekia Sada(BSc. In Software Engineering) Page
11
7. Next, create a string for the current date that is formatted for your culture or
region by using the DateTime.ToString method.
The first argument for the method specifies how the date should be
displayed. This example uses the format specifier (d) which indicates the short
date format.
The second argument is the CultureInfo object that specifies the culture or
region for the date. The second argument determines, among other things,
the language of any words in the date, and the type of separators used.
1. Notice that a wavy underline appears under CultureInfo. The wavy underline appears
because this type isn't in scope
Open the Error List toolbar to see the same error listed there. If you don't see the Error
List toolbar, go to View > Error List from the top menu bar
2. Let's fix this error. In the code editor, place your cursor on the line that contains
the error, and then select the Quick Actions light bulb in the left margin. Then,
from the drop-down menu, select using System.Globalization; to add this
directive to the top of your file and resolve the errors.
Starting with C# & ASP.NET in Visual Studio- By Metekia Sada(BSc. In Software Engineering) Page
12
3. Press F5 to open your project in the web browser.
4. At the top of the web site, select Privacy to view your changes.
Starting with C# & ASP.NET in Visual Studio- By Metekia Sada(BSc. In Software Engineering) Page
13
The Index.cshtml file corresponds with your Home page in the web app, which
runs in a web browser.
In the code editor, you'll see HTML code for the text that appears on the Home page.
Starting with C# & ASP.NET in Visual Studio- By Metekia Sada(BSc. In Software Engineering) Page
14
2. Replace the Welcome text with Hello World!
3. Select IIS Express or press Ctrl+F5 to run the app and open it in a web browser.
4. In the web browser, you'll see your new changes on the Home page
5. Close the web browser, press Shift+F5 to stop debugging, and save your project. You
can now close Visual Studio
Starting with C# & ASP.NET in Visual Studio- By Metekia Sada(BSc. In Software Engineering) Page
15
Starting with C# & ASP.NET in Visual Studio- By Metekia Sada(BSc. In Software Engineering) Page
16