Link to home
Start Free TrialLog in
Avatar of BeginningWebDesign
BeginningWebDesign

asked on

System.Web.HttpRequestValidationException

Hello EE Community

Does anyone know how to redirect a site visitor to another page if the System.Web.HttpRequestValidationException detects an invalid form entry.

I have tried the following but recieve an error:
void Page_Init()
{
if(System.Web.HttpRequestValidationException == true)
Response.Redirect("index.aspx");
  }

Compiler Error Message: CS0118: 'System.Web.HttpRequestValidationException' denotes a 'class' where a 'variable' was expected

Source Error:

 

Line 44: void Page_Init()
Line 45: {
Line 46: if(System.Web.HttpRequestValidationException == true)
Line 47: Response.Redirect("index.aspx");
Line 48:   }
 

Source File: C:\*** Line: 46

Thank you in advance
Caz
Avatar of tovvenki
tovvenki

HI,
use the try ..catch block like

try
{
//your code here
}catch(System.Web.HttpRequestValidationException ex)
{
     Response.Redirect("index.aspx");
}

regards,
venki
 Hello,
  An exception is automatically thrown by the system if one exception occurs. The HttpRequestValidationException exception that is thrown when a potentially dangerous input string is received from the client.
  You can use try-catch block to catch the exception and redirect users according to your need.

  Tri

SOLUTION
Avatar of msreekm
msreekm
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BeginningWebDesign

ASKER

Thanks for the reply everyone
As I'm new to EE, can you tell me what I need to do about the answers supplied by  ihenry  and msreekm  as both relate to the same subject.

I tried tovvenki  code but that did not work.

The other option to this question would be how can I validate a form on the server side when it is being posted to another page.

The two text boxes are strUsername and strPassword and the regular expression I'm using to validate them are: "^[^<>`~!/ \#}$%:;)(_^{&*=|'+]+$"

Caz