Solved

System.Web.HttpRequestValidationException

Posted on 2004-08-08
6
1,328 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Finally almost got it 5 48
FTP file download using c# 3 25
Get distinct values from excel or comm seperated file 4 32
need to convert function to c# 5 30
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

828 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