Solved

System.Web.HttpRequestValidationException

Posted on 2004-08-08
6
1,334 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

Technology Partners: 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!

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

734 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