3

I want to redirect all errors to one error page, so in the web.config file, i have inserted :

<httpErrors errorMode="Custom" existingResponse="Auto" defaultPath="/error.html" defaultResponseMode="Redirect">

It works fine but I want to add more option. here is how I want it to be :

Imagine the url of the website is : www.examplesite.com

I want when the viewers changed the url like this :

www.examplesite.com/aaaaaaa

it will be redirect to :

www.examplesite.com/error.html?path=aaaaaaa

I do not know how can I implement this .

thanks in advance.

Cool Mike
  • 65
  • 8

1 Answers1

2

Something like this should do

<httpErrors errorMode="Custom" existingResponse="Replace">
  <remove statusCode="404"/>
  ...
  <error statusCode="404" responseMode="ExecuteURL" path="Path to your error page"/>
 ...
</httpErrors>

Incase you want to know the differen between customErrors and httpErrors you can refer to this answer

Community
  • 1
  • 1
Izzy
  • 6,740
  • 7
  • 40
  • 84
  • Thanks , but as i mentioned in the title of question, i want to pass the bad input to the url as i said in the question but your answer does not provide what i want. – Cool Mike Apr 23 '15 at 09:25
  • Have you even tried the code? Because it's similar to what I use and it passes the bad input to the url – Izzy Apr 23 '15 at 09:45
  • 1
    yes I have tried your answer but it shows only the error page, nothing happend in the url . – Cool Mike Apr 23 '15 at 14:35
  • Note:It does not redirect, it will transfer execution. Hence you will not see the query string in your browser, but parameters are accessible in code on the executed url. the querystring is in this format `?500;http://example.com/news/?page=a` where 500 is the status code, and the original url follows the `;` – Myster Oct 10 '16 at 23:11