Click here to Skip to main content
15,913,361 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: google map in VB.NET Pin
Abhishek Sur6-Jan-10 20:51
professionalAbhishek Sur6-Jan-10 20:51 
QuestionSQl Pin
Hema Bairavan1-Jan-10 6:58
Hema Bairavan1-Jan-10 6:58 
AnswerRe: SQl Pin
Brij1-Jan-10 7:21
mentorBrij1-Jan-10 7:21 
GeneralRe: SQl Pin
Hema Bairavan1-Jan-10 7:39
Hema Bairavan1-Jan-10 7:39 
GeneralRe: SQl Pin
Brij1-Jan-10 19:04
mentorBrij1-Jan-10 19:04 
AnswerRe: SQl Pin
Abhijit Jana1-Jan-10 7:52
professionalAbhijit Jana1-Jan-10 7:52 
GeneralRe: SQl Pin
Hema Bairavan1-Jan-10 7:53
Hema Bairavan1-Jan-10 7:53 
QuestionHow to handle request validation exception Pin
THE SK1-Jan-10 5:48
THE SK1-Jan-10 5:48 
Hi All

I have the following code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<script language="C#" runat="server">

protected void button1_Click(object sender, EventArgs e)
{
try
{
TextBox1.Text = (TextBox1.Text + "<strong></strong>");
Label1.Text = (TextBox1.Text);
}
catch (System.Web.HttpRequestValidationException)
{
Response.Write("html is not allowed");
}
}

</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Height="300px" Width="400px"></asp:TextBox>
</div>
<asp:Button ID="button1" runat="server" Text="strong" onclick="button1_Click" />
<asp:Label ID="Label1" runat="server"></asp:Label>

</form>
</body>
</html>


If i click on button twice I am getting request validation exception which I want to catch.

The error which I am getting is

*************************************************************************

Server Error in '/TextControlOnSite' Application.
--------------------------------------------------------------------------------

A potentially dangerous Request.Form value was detected from the client (TextBox1="<strong></strong>").
Description: Request Validation has detected a potentially dangerous client input value, and processing of the request has been aborted. This value may indicate an attempt to compromise the security of your application, such as a cross-site scripting attack. You can disable request validation by setting validateRequest=false in the Page directive or in the configuration section. However, it is strongly recommended that your application explicitly check all inputs in this case.

Exception Details: System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client (TextBox1="<strong></strong>").

Source Error:


[No relevant source lines]


Source File: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\textcontrolonsite\d5a3eadf\30926e30\App_Web_rwvmmuiv.0.cs Line: 0

Stack Trace:


[HttpRequestValidationException (0x80004005): A potentially dangerous Request.Form value was detected from the client (TextBox1="<strong></strong>").]
System.Web.HttpRequest.ValidateString(String s, String valueName, String collectionName) +3310274
System.Web.HttpRequest.ValidateNameValueCollection(NameValueCollection nvc, String collectionName) +108
System.Web.HttpRequest.get_Form() +119
System.Web.HttpRequest.get_HasForm() +3312222
System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull) +45
System.Web.UI.Page.DeterminePostBackMode() +65
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +7350
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +213
System.Web.UI.Page.ProcessRequest() +86
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +18
System.Web.UI.Page.ProcessRequest(HttpContext context) +49
ASP.default_aspx.ProcessRequest(HttpContext context) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\textcontrolonsite\d5a3eadf\30926e30\App_Web_rwvmmuiv.0.csBlush | :O
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +358
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.1873; ASP.NET Version:2.0.50727.1433


***************************************************************************




I have put try catch block but it is not executing.
I know that we can use Server.HtmlEncode and Server.HtmlDecode method and also knows that ValidateRequest property of page attribute.But in my case i want to execute some code only on this page when the RequestValidation Exception occurs.
I donot want to handle error in global.asax file.
I want to handle error on this page only.

Please suggest.

Thanks

Regards
Sandeep
AnswerRe: How to handle request validation exception Pin
Anurag Gandhi1-Jan-10 6:39
professionalAnurag Gandhi1-Jan-10 6:39 
AnswerRe: How to handle request validation exception Pin
Brij1-Jan-10 7:20
mentorBrij1-Jan-10 7:20 
QuestionProblem in sending email [modified] Pin
Khaled.Hossain1-Jan-10 5:05
Khaled.Hossain1-Jan-10 5:05 
AnswerRe: Problem in sending email Pin
Brij1-Jan-10 5:17
mentorBrij1-Jan-10 5:17 
AnswerRe: Problem in sending email Pin
Khaled.Hossain1-Jan-10 5:30
Khaled.Hossain1-Jan-10 5:30 
GeneralRe: Problem in sending email Pin
AhsanS1-Jan-10 5:38
AhsanS1-Jan-10 5:38 
GeneralRe: Problem in sending email Pin
Brij1-Jan-10 6:04
mentorBrij1-Jan-10 6:04 
GeneralRe: Problem in sending email Pin
Khaled.Hossain1-Jan-10 16:27
Khaled.Hossain1-Jan-10 16:27 
QuestionFacebook like portal Pin
syedsaqib1-Jan-10 4:08
syedsaqib1-Jan-10 4:08 
AnswerRe: Facebook like portal Pin
AhsanS1-Jan-10 5:40
AhsanS1-Jan-10 5:40 
QuestionHow to read available control from a aspx file? Pin
Md. Marufuzzaman31-Dec-09 23:26
professionalMd. Marufuzzaman31-Dec-09 23:26 
AnswerRe: How to read available control from a aspx file? Pin
N a v a n e e t h1-Jan-10 3:09
N a v a n e e t h1-Jan-10 3:09 
GeneralRe: How to read available control from a aspx file? Pin
Abhijit Jana1-Jan-10 3:49
professionalAbhijit Jana1-Jan-10 3:49 
GeneralRe: How to read available control from a aspx file? Pin
N a v a n e e t h1-Jan-10 3:57
N a v a n e e t h1-Jan-10 3:57 
GeneralRe: How to read available control from a aspx file? Pin
Md. Marufuzzaman1-Jan-10 3:59
professionalMd. Marufuzzaman1-Jan-10 3:59 
GeneralRe: How to read available control from a aspx file? Pin
N a v a n e e t h1-Jan-10 4:20
N a v a n e e t h1-Jan-10 4:20 
GeneralRe: How to read available control from a aspx file? Pin
Md. Marufuzzaman1-Jan-10 5:15
professionalMd. Marufuzzaman1-Jan-10 5:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.