My Problem
right now, when I run my dotnet build I can’t see anything on the webpage. On chrome I get :
This site can’t provide a secure connectionlocalhost sent an invalid response.
ERR_SSL_PROTOCOL_ERROR
On Safari I can see a plain site.
Setup
I got visual studio code and .Net 6.0.421.
Project structure
-Controllers--HomeController.cs
-TeachingPlanController.cs
-Modells--ErrorViewModell.cs
-Lesson.cs
-LessonViewModell.cs
-TeachingPlanViewModell.cs
-Properties
-Viewes--Home--Index.cshtml
-Shared
-TeachingPlan--Index.cshtml
-appsetting.Development.json
-appsetting.json
-Programm.cs
-SoPro24Team01.csproj
My Code
TeachingPlanController.cs:
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using SoPro24Team01.Models;
namespace SoPro24Team01.Controllers
{
[Route("[controller]")]
public class TeachingPlanController : Controller
{
public ViewResult Index()
{
var lessons = new List<Lesson>
{
new Lesson(1, "Introduction to Programming", "http://example.com/deck1", TimeSpan.FromHours(1)),
new Lesson(2, "Data Structures and Algorithms", "http://example.com/deck2", TimeSpan.FromHours(2)),
new Lesson(3, "Web Development Basics", "http://example.com/deck3", TimeSpan.FromHours(3))
};
var lessonViewModels = lessons.Select(lesson => new LessonViewModel
{
Lesson = lesson
}).ToList();
var viewModel = new TeachingPlanViewModel
{
Lessons = lessonViewModels
};
return View(viewModel);
}
}
}
Lesson.cs:
namespace SoPro24Team01.Models
{
public class Lesson
{
private int id;
public int Id
{
get { return id; }
set { id = value; }
}
private string? name;
public string? Name
{
get { return name; }
set { name = value; }
}
private string? cardDeckLink;
public string? CardDeckLink
{
get { return cardDeckLink; }
set { cardDeckLink = value; }
}
private TimeSpan timeEstimation;
public TimeSpan TimeEstimation
{
get { return timeEstimation; }
set { timeEstimation = value; }
}
public Lesson(int id, string name, string cardDeckLink, TimeSpan timeEstimation)
{
Id = id;
Name = name;
CardDeckLink = cardDeckLink;
TimeEstimation = timeEstimation;
}
}
}
LessonViewModel.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace SoPro24Team01.Models
{
public class LessonViewModel
{
public Lesson? Lesson { get; set; }
}
}
TeachingPlanViewModel.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace SoPro24Team01.Models
{
public class TeachingPlanViewModel
{
public List<LessonViewModel>? Lessons { get; set; }
public string? Title { get; set; }
public string? Header { get; set; }
}
}
Now my Index (in /views/TeachingPlan) page:
@model SoPro24Team01.Models.TeachingPlanViewModel
<html>
<head>
</head>
<body>
<p>This is a test</p>
</body>
</html>
the programm.cs:
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=TeachingPlan}/{action=Index}/{id?}");
app.Run();
I changed in this file controller=Home to controller=TeachingPlan but that didn’t helped. I don’t know what wrong.