c# - How to return 404 page if illegal character in path error is met in ASP.NET MVC -


i have asp.net mvc application, have own error handling module like:

public class errorhandlingmodule : ihttpmodule {       public void init( httpapplication context )       {          context.error += context_error;       }        public void dispose() { }        void context_error( object sender, eventargs e ) { }  } 

there treat different type of exceptions httpexception , other type of custom exceptions.

i want check if illegal characters in path exception met returns 404 page. (like user insert http://www.website.com/test")

by default returns 500 error page.

what's better way ? comparing exception's message, hresult ... ?

you change status of httpresponse notfound (404):

response.statuscode = httpstatuscode.notfound; 

you can response current context, weboperationcontext.current.outgoingresponse.

if trying capture bad incoming request - is, uri of request has invalid path characters - have fight wcf or reconfigure information, processed chain of message handlers before ever dispatched application.


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -