You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have configured ASP.NET Core default Exception Handler as follows:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
//app.UseHsts();
}
}
Whenever any error occurs in the GET methods, it is working as expected that is it is being caught and redirected to the Error() method.
Problem is that whenever any error occurs in the POST methods, it is not working as expected that is it is not being caught and redirected to the Error() method.
Here is sample code:
public class HomeController : Controller
{
// GET: ContactInfo/Create
public async Task<IActionResult> Create()
{
Convert.ToInt32("Hello"); // Intentional error
return View();
}
// POST: ContactInfo/Create
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(ContactInfo contactInfo)
{
Convert.ToInt32("Hello"); // Intentional error
if (ModelState.IsValid)
{
return RedirectToAction(nameof(Index));
}
return View(contactInfo);
}
[HttpGet]
[Route("/Error/{id?}")]
public IActionResult Error(int? id)
{
if (id == 404)
{
return View("PageNotFound");
}
var feature = HttpContext.Features.Get<IExceptionHandlerPathFeature>();
// Necessary staffs here
return View();
}
}
The text was updated successfully, but these errors were encountered:
TanvirArjel
changed the title
app.UseExceptionHandler("/Error"); doesn't work on POST method.
app.UseExceptionHandler("/Error"); doesn't work on POST methods.
Sep 25, 2018
I have configured ASP.NET Core default Exception Handler as follows:
Whenever any error occurs in the
GET
methods, it is working as expected that is it is being caught and redirected to theError()
method.Problem is that whenever any error occurs in the
POST
methods, it is not working as expected that is it is not being caught and redirected to theError()
method.Here is sample code:
The text was updated successfully, but these errors were encountered: