Solved

System.Web.HttpRequestValidationException

Posted on 2004-08-08
6
1,336 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:BeginningWebDesign
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 21

Expert Comment

by:tovvenki
ID: 11750202
HI,
use the try ..catch block like

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

regards,
venki
0
 
LVL 7

Expert Comment

by:dttri
ID: 11750348
 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

0
 
LVL 4

Assisted Solution

by:msreekm
msreekm earned 250 total points
ID: 11750607
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Accepted Solution

by:
ihenry earned 250 total points
ID: 11755446
Hi Caz

Unlike any other exceptions which you can catch them and continue with normal page execution, you can't do as such after this exception type occured. Unless you disable this feature and rely on Server.HtmlEncode and Server.HtmlDecode for handling input.

The link provided by Sree should gives some work arounds, unfortunately it's showing error page instead. Try this link, I hope you won't see the same error when you open it :)

Handling ValidateRequest errors within a Page
http://weblogs.asp.net/kaevans/archive/2003/07/07/9791.aspx

HTH
0
 

Author Comment

by:BeginningWebDesign
ID: 11761326
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
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question