I'm newbie about Asp.net core, I have an assignment about creating a create,edit,delete,detail Users in a table on database page. and I met mine as the title says, I really don't know what to do to fix it
This is my programs.cs file
using EditUserRazor.Data;
using Microsoft.EntityFrameworkCore;
using EditUserRazor.Models;
namespace EditUserRazor {
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
//DI
builder.Services.AddDbContext<UserDbContext>(options => options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/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.MapRazorPages();
app.Run();
}
}
}
}
This is my appsetting.json file
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"DefautConnection": "server=LENOVO_NOV\\MSSQLEXPRESS;database=KiemTra2;integrated security=true;trustservercertificate=true"
}
}
Hope you can help!
Your connection string name used inside your codes(DefaultConnection) if different than you set inside the appsetting.json(DefautConnection).
I suggest you modify the config like below: