I think question is clear. I want to handle url strings which can be added by user.
Example;
http://download.cnet.com/windows/script alert('hello') /script
or
http://download.cnet.com/windows/aaaaaaaaaaaaa
As you can see in examples, cnet handle these inputs and redirect user to custom 404 file.
I’m working on mvc3 razor, it’s something with controller I suppose, but I can’t make it.
Extra Information:
What I want to do; I want to handle or external string which can be added end of the url.
Another example; http://www.yazilimdevi.com/yazilimdevi/aaaaaaaaa
As you can see, if user input “aaaaaa” to end of url; he/she see “Server Error in Application” which was prepared by IIS. I want to create a custom page, and redirect all users who added unknown path, string or script…
Thanks…
If you want to implement special handling for this scenario then you may want to add new route using
/{*arbitrary_url_part}scheme. For example, routewill match all those urls:
http://Server_url/constant_path/(variable_part==””)http://Server_url/constant_path/aaaaaaaaaaaaa(variable_part==”aaaaaaaaaaaaa”)http://Server_url/constant_path/script alert('hello') /script(variable_part==”script alert(‘hello’) /script”)etc. no matter how much slashes or other special symbols user puts in. For reference, see MSDN: ASP.NET Routing – Handling a Variable Number of Segments in a URL Pattern
.
If you don’t want to bother yourself with implementing all this stuff and only want to show a fancy 404 page to user then you might consider using standard ASP.NET feature – Custom error pages
Other strategies on handling such requests can also be found in This blog post.
UPDATE
If you want to go the first way, you’ll also have to add controller and view for displaying some custom error page. If you take the same names as in route you’ll have to add following to your project:
File
Controllers/ErrorController.cscontaining classErrorControllerwith methodShowError, like this:File
Views/Error/ShowError.aspx– a simple HTML view to display error information, like this: