Solved

System.Web.HttpRequestValidationException

Posted on 2004-08-08
6
1,322 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
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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
 
LVL 20

Expert Comment

by:ihenry
ID: 11761408
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now