c# - HTTP Error 404.0 - Not Found in MVC 5 -


my project in mvc 5.i wanted handel 404. did problem

when access view using following url, works fine , expected:

http://localhost/hotels/index30701000000 

but when access view using following url, 404.0 error message (error shown below)

http://localhost/hotels/edit/09099999dfdfb                        http://localhost/hotels/edit/090/20130701000000 

error: http error 404.0 - not found resource looking has been removed, had name changed, or temporarily unavailable.

my code is

controller

public class errorcontroller : controller {     // get: error     public actionresult unauthorized()     {         response.statuscode = 404;         response.tryskipiiscustomerrors = true;         return view();     } } 

routeconfig

    routes.maproute(         name: "unauthorized",         url: "unauthorized/{action}/{id}",         defaults: new         {             controller = "error",             action = "unauthorized",             id = urlparameter.optional         }     ); 

global.asax

    protected void application_error()     {         exception exception = server.getlasterror();         httpexception httpexception = exception httpexception;     } 

webconfig

  <system.web>     <customerrors mode="on" defaultredirect="error">       <error statuscode="404" redirect="unauthorized" />     </customerrors>   </system.web> 

view //unauthorized.cshtml

@model system.web.mvc.handleerrorinfo @{     viewbag.title = "unauthorized"; } <h1>page not found!</h1> 

reference link

just write these lines of code in global.asax file of application.

protected void application_endrequest()     {         if (context.response.statuscode == 404)         {             if ((!request.rawurl.contains("style")) && (!request.rawurl.contains("images")))             {                 response.clear();                 if (response.statuscode == 404)                 {                     response.redirect("/controllername/actionname");                 }             }         }     } 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -