diff --git a/Website/Controllers/BlogController.cs b/Website/Controllers/BlogController.cs index f0f76d9..92f8a0f 100644 --- a/Website/Controllers/BlogController.cs +++ b/Website/Controllers/BlogController.cs @@ -30,9 +30,13 @@ namespace Website.Controllers public async Task Entry(string url) { - var post = await _repo.GetPostByUrlAsync(url); - var model = new BlogPostViewModel(post); - return View(model); + try { + var post = await _repo.GetPostByUrlAsync(url); + var model = new BlogPostViewModel(post); + return View(model); + } catch (InvalidOperationException e) { + return NotFound(); + } } } } diff --git a/Website/Startup.cs b/Website/Startup.cs index 79d7a9b..6d6adf4 100644 --- a/Website/Startup.cs +++ b/Website/Startup.cs @@ -40,18 +40,18 @@ namespace Website // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { - if (env.IsDevelopment()) + if (env.IsDevelopment() ) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error/ServerError"); - app.UseStatusCodePagesWithReExecute("/Error/PageNotFound"); // 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.UseStatusCodePagesWithReExecute("/Error/PageNotFound"); app.UseHttpsRedirection(); app.UseStaticFiles();