ASP.NET Core Razor
【データエラー】
だいたいこちらのサイトの通りしたらうまくデータベースを含んだアプリケーションができます。ただし唯一引っかかった部分をノートしときます。
Tutorial: Create a Razor Pages web app with ASP.NET Core
このチュートリアルが終わったのち、最初のパブリッシュが終わったら必ず『RazorPagesMovieContext』➡『DefaultConnection』におきかえること!!!
『Startup.cs』
namespace RazorPagesMovie
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
services.AddDbContext<RazorPagesMovieContext>(options =>
// options.UseSqlServer(Configuration.GetConnectionString("RazorPagesMovieContext")));
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
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.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
});
}
}
}
『appsettings.json』
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
// "RazorPagesMovieContext": " Server=(localdb)\\mssqllocaldb;Database=RazorPagesMovieContext-63de2d6b-2550-4619-9509-b951fc76092b;Trusted_Connection=True;MultipleActiveResultSets=true",
"DefaultConnection": " Server=(localdb)\\mssqllocaldb;Database=RazorPagesMovieContext-63de2d6b-2550-4619-9509-b951fc76092b;Trusted_Connection=True;MultipleActiveResultSets=true"
}
}
※コメント投稿者のブログIDはブログ作成者のみに通知されます