I'm using asp.net MVC4 + visual studio 2012. every thing all fine, But only the custom error always has the aspxerrorpath param on the URL.
I already config the custom error on web.config:
<customErrors mode="On" defaultRedirect="~/Error/Error">
<error redirect="~/Error/Error" statusCode="404" />
<error redirect="~/Error/Error" statusCode="500" />
</customErrors>
I also changed my Error Action to :
public ActionResult Error()
{
Response.Status = "404 Not Found";
Response.StatusCode = 404;
return View();
}
Will now when there is some 404 happening. I always got aspxerrorpath param on my URL.
I tried add redirectMode="ResponseRewrite"
to the customError nodes but If add this , the error will display a run time exception.....
So Is there any best way to remove the aspxerrorpath param? Thanks.
Click the Custom Errors tab. Select Off for custom error mode. Or navigate to the folder containing your application and open the web. config file in a text editor and edit by hand, and change the custom errors tag to <customErrors mode="Off" />.
You can handle default errors and HTTP errors by adding a customErrors section to the Web. config file. The customErrors section allows you to specify a default page that users will be redirected to when an error occurs. It also allows you to specify individual pages for specific status code errors.
Use the defaultRedirect to specify where an http request should be redirect by default if an error occurs. You can specify the name of a webform, an HTML, or an action method. This will redirect to this page on any error code, not just 500.
Another simple solution is turning on customErrors
in web.config
file for 404 error:
<customErrors mode="On">
<error statusCode="404" redirect="~/home/notfound" />
</customErrors>
and in home controller:
public ActionResult NotFound(string aspxerrorpath)
{
if (!string.IsNullOrWhiteSpace(aspxerrorpath))
return RedirectToAction("NotFound");
return View();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With