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>
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");
    }
}
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();
    }

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();
        }
    }

Comments

Your Answer

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.