Skip to content

Commit 01eea6f

Browse files
Session 1
1 parent 0fc735e commit 01eea6f

32 files changed

+14508
-0
lines changed

CMS.csproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<PropertyGroup Condition=" '$(RunConfiguration)' == 'https' " />
10+
<PropertyGroup Condition=" '$(RunConfiguration)' == 'http' " />
11+
<ItemGroup>
12+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="7.0.10" />
13+
</ItemGroup>
14+
</Project>

CMS.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 25.0.1706.3
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CMS", "CMS.csproj", "{D11EF63C-52B6-4350-922B-32402DB67BF2}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{D11EF63C-52B6-4350-922B-32402DB67BF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{D11EF63C-52B6-4350-922B-32402DB67BF2}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{D11EF63C-52B6-4350-922B-32402DB67BF2}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{D11EF63C-52B6-4350-922B-32402DB67BF2}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {1E808469-D5DF-4135-A16A-FA90CDDCBAFE}
24+
EndGlobalSection
25+
EndGlobal

Controllers/HomeController.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System.Diagnostics;
2+
using Microsoft.AspNetCore.Mvc;
3+
using CMS.Models;
4+
5+
namespace CMS.Controllers;
6+
7+
public class HomeController : Controller
8+
{
9+
private readonly ILogger<HomeController> _logger;
10+
11+
public HomeController(ILogger<HomeController> logger)
12+
{
13+
_logger = logger;
14+
}
15+
16+
public IActionResult Index()
17+
{
18+
return View();
19+
}
20+
21+
public IActionResult About()
22+
{
23+
string admin = "Jingcheng";
24+
25+
ViewBag.admin = admin;
26+
27+
return View();
28+
}
29+
30+
public IActionResult Privacy()
31+
{
32+
return View();
33+
}
34+
35+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
36+
public IActionResult Error()
37+
{
38+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
39+
}
40+
}
41+

Models/ErrorViewModel.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace CMS.Models;
2+
3+
public class ErrorViewModel
4+
{
5+
public string? RequestId { get; set; }
6+
7+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
8+
}
9+

Program.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
var builder = WebApplication.CreateBuilder(args);
2+
3+
// Add services to the container.
4+
builder.Services.AddControllersWithViews();
5+
6+
builder.Services.AddRazorPages().AddRazorRuntimeCompilation();
7+
8+
var app = builder.Build();
9+
10+
11+
// Configure the HTTP request pipeline.
12+
if (!app.Environment.IsDevelopment())
13+
{
14+
app.UseExceptionHandler("/Home/Error");
15+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
16+
app.UseHsts();
17+
}
18+
19+
app.UseHttpsRedirection();
20+
app.UseStaticFiles();
21+
22+
app.UseRouting();
23+
24+
app.UseAuthorization();
25+
26+
app.MapControllerRoute(
27+
name: "default",
28+
pattern: "{controller=Home}/{action=Index}/{id?}");
29+
30+
app.Run();
31+

Properties/launchSettings.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:12766",
8+
"sslPort": 44309
9+
}
10+
},
11+
"profiles": {
12+
"http": {
13+
"commandName": "Project",
14+
"launchBrowser": true,
15+
"applicationUrl": "http://localhost:5071",
16+
"environmentVariables": {
17+
"ASPNETCORE_ENVIRONMENT": "Development"
18+
},
19+
"dotnetRunMessages": true
20+
},
21+
"https": {
22+
"commandName": "Project",
23+
"launchBrowser": true,
24+
"applicationUrl": "https://localhost:7283;http://localhost:5071",
25+
"environmentVariables": {
26+
"ASPNETCORE_ENVIRONMENT": "Development"
27+
},
28+
"dotnetRunMessages": true
29+
},
30+
"IIS Express": {
31+
"commandName": "IISExpress",
32+
"launchBrowser": true,
33+
"environmentVariables": {
34+
"ASPNETCORE_ENVIRONMENT": "Development"
35+
}
36+
}
37+
}
38+
}

Views/Home/About.cshtml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@{
2+
ViewData["Title"] = "About";
3+
}
4+
5+
<div class="p-16 bg-grey-100 dark:bg-black min-h-screen">
6+
<p class="dark:text-white font-bold text-2xl md:text-6xl">About Our Website</p>
7+
<p>This is about our new CMS system</p>
8+
9+
<p>Our System Admin is: @ViewBag.admin</p>
10+
11+
<div class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-5 lg:grid-cols-7 gap-8 mt-4">
12+
@for (int i = 0; i < 10; i++)
13+
{
14+
<p class="p-4 bg-gray-100 rounded-lg shadow-xl">Helglo World @(i*10)</p>
15+
}
16+
</div>
17+
18+
<div class="mt-4">
19+
<a class="btn btn-sm md:btn-md xl:btn-lg btn-neutral btn-outline">Privacy</a>
20+
</div>
21+
</div>

Views/Home/Index.cshtml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@{
2+
ViewData["Title"] = "Home Page";
3+
}
4+
5+
<div class="text-center">
6+
<h1 class="display-4">Welcome</h1>
7+
<p>Learn about <a href="https://learn.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
8+
</div>

Views/Home/Privacy.cshtml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@{
2+
ViewData["Title"] = "Privacy Policy";
3+
}
4+
<h1>@ViewData["Title"]</h1>
5+
6+
<p>Use this page to detail your site's privacy policy.</p>
7+

Views/Shared/Error.cshtml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@model ErrorViewModel
2+
@{
3+
ViewData["Title"] = "Error";
4+
}
5+
6+
<h1 class="text-danger">Error.</h1>
7+
<h2 class="text-danger">An error occurred while processing your request.</h2>
8+
9+
@if (Model.ShowRequestId)
10+
{
11+
<p>
12+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
13+
</p>
14+
}
15+
16+
<h3>Development Mode</h3>
17+
<p>
18+
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
19+
</p>
20+
<p>
21+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
22+
It can result in displaying sensitive information from exceptions to end users.
23+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
24+
and restarting the app.
25+
</p>
26+

0 commit comments

Comments
 (0)