Throw 404 when blog post fails to load.
This commit is contained in:
parent
40e8899368
commit
6c905f177f
2 changed files with 9 additions and 5 deletions
|
@ -30,9 +30,13 @@ namespace Website.Controllers
|
||||||
|
|
||||||
public async Task<IActionResult> Entry(string url)
|
public async Task<IActionResult> Entry(string url)
|
||||||
{
|
{
|
||||||
var post = await _repo.GetPostByUrlAsync(url);
|
try {
|
||||||
var model = new BlogPostViewModel(post);
|
var post = await _repo.GetPostByUrlAsync(url);
|
||||||
return View(model);
|
var model = new BlogPostViewModel(post);
|
||||||
|
return View(model);
|
||||||
|
} catch (InvalidOperationException e) {
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,18 +40,18 @@ namespace Website
|
||||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
||||||
{
|
{
|
||||||
if (env.IsDevelopment())
|
if (env.IsDevelopment() )
|
||||||
{
|
{
|
||||||
app.UseDeveloperExceptionPage();
|
app.UseDeveloperExceptionPage();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
app.UseExceptionHandler("/Error/ServerError");
|
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.
|
// 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.UseHsts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.UseStatusCodePagesWithReExecute("/Error/PageNotFound");
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue