0

I've set up my webconfig to custom error pages. But it doesn't work. I create a controller and action with name "hata". I can see this page "http://localhost/hata/bulunamadi" but when i try to open not exists page so my custom error pages doesn't show. (i see iss default 404 page)

<system.web> 
<customErrors defaultRedirect="~/hata/bulunamadi" redirectMode="ResponseRewrite" mode="On">
 <error statusCode="404" redirect="~/hata/bulunamadi"/>
</customErrors>
</system.web>
asked Jun 3, 2015 at 21:53
1
  • Custom Error relies on ErrorController. How does it look like? Commented Jun 3, 2015 at 22:02

3 Answers 3

2
<customErrors mode="On" defaultRedirect="~/Error">
 <error redirect="~/Error/NotFound" statusCode="404" />
</customErrors>

And the controller contains the following:

public class ErrorController : Controller
{
 public ViewResult Index()
 {
 return View("Error");
 }
 public ViewResult NotFound()
 {
 Response.StatusCode = 404; //you may want to set this to 200
 return View("NotFound");
 }
}
answered Jun 4, 2015 at 4:28
Sign up to request clarification or add additional context in comments.

Comments

0

try this

Web.Config

 <system.web>
 <customErrors mode="On" defaultRedirect="Error">
 <error statusCode="404" redirect="NotFound" />
 </customErrors> 
</system.web>

create Error.cshtml and NotFound.cshtml in shared folder Create an ErrorController

 public ActionResult Error()
 {
 return View();
 }
answered Jun 3, 2015 at 22:02

Comments

0

Please follow step by step this description : First, you have to settings up your web config for custom page error. Just like this

<system.web>
 <customErrors mode="On" defaultRedirect="~/Error/" redirectMode="ResponseRedirect">
 <error statusCode="404" redirect="~/Error/Error404/" />
 <error statusCode="500" redirect="~/Error/Error500/" />
 <error statusCode="400" redirect="~/Error/Error400/" />
 </customErrors>
</system.web>

Then you have to configure your RouteConfig.cs :

routes.MapRoute(
 name: "Default",
 url: "{controller}/{action}/{id}",
 defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
 "404-PageNotFound",
 "{*url}",
 new { controller = "Error", action = "Error404" }
);

And finally, you have to create your custom error View and Action :

public class ErrorController : Controller
 {
 // GET: Error
 public ActionResult Index()
 {
 return View();
 }
 public ViewResult Error404()
 {
 return View();
 }
 public ViewResult Error500()
 {
 return View();
 }
 public ViewResult Error400()
 {
 return View();
 }
 public ActionResult General()
 {
 return View();
 }
 }
answered Aug 9, 2019 at 20:20

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.