Exact Place where Request.ValidateInput Function - asp.net

which is the Exact Place where Request.ValidateInput Function is calling during the ProcessRequest Phase..? (in asp.net 2.0)

RequestValidation fires very early in the lifecycle.
These events & methods fire and then at the DeterminePostBackMode point the request is terminated.
ExecuteStep
Execute
BeginProcessRequest
ProcessRequestInternal
ProcessRequestWithNoAssert
ProcessRequest
ProcessRequestMain
DeterminePostBackMode
Here's an example stacktrace from a HttprequestValidationException.
at System.Web.HttpRequest.ValidateString(String s, String valueName, String collectionName)
at System.Web.HttpRequest.ValidateNameValueCollection(NameValueCollection nvc, String collectionName)
at System.Web.HttpRequest.get_Form()
at System.Web.HttpRequest.get_HasForm()
at System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull)
at System.Web.UI.Page.DeterminePostBackMode()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.register_aspx.ProcessRequest(HttpContext context) in d:\Temporary ASP.NET Files\belfast\09a30891\d8a3024a\App_Web_fxdlie1w.16.cs:line 0
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Thanks,
Phil.

Related

A generic error occurred in GDI+ - On specific server only

I have the following piece of code that turns an image into a byte array to store in the database.
Public Function Image2Bytes(ByRef aImage As Drawing.Image) As Byte()
Dim MemStream As New MemoryStream()
aImage.Save(MemStream, Drawing.Imaging.ImageFormat.Png)
Return MemStream.ToArray()
End Function
This works fine on our local server as well as some production servers. However, on some shared hosting servers, this gives a GDI+ error as described below:
Error: Exception of type 'System.Web.HttpUnhandledException' was thrown. > A generic error occurred in GDI+.:
Top Stack Trace:
System.Web.UI.Page.HandleError(Exception e)
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
System.Web.UI.Page.ProcessRequest()
System.Web.UI.Page.ProcessRequest(HttpContext context)
System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Inner Stack Trace:
System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
Common.Image2Bytes(Image& aImage)
EntityClass.Validate()
Logo.Page_Load(Object sender, EventArgs e)
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
I've seen a lot of "Generic GDI+" errors here, but none of them solve this issue. For each solution I need to upload to a specific production server to test, as locally, there is no error.
Any ideas?

An item with the same key has already been added. (Ajaxcontroltoolkit)

Can anyone help with this issue? I recieve this error in our logs every so often but the users say they didnt experience any issues.
Thanks
Error Description
Exception of type 'System.Web.HttpUnhandledException' was thrown.Inner
Exception-->An item with the same key has already been added. -
System.ArgumentException: An item with the same key has already been
added. at System.Collections.Generic.Dictionary`2.Insert(TKey key,
TValue value, Boolean add) at
AjaxControlToolkit.ToolkitScriptManagerHelper.GetAssembly(String name)
at
AjaxControlToolkit.ToolkitScriptManagerCombiner.IsScriptCombinable(ScriptEntry
scriptEntry, Boolean enableCdn) at
AjaxControlToolkit.ToolkitScriptManagerCombiner.WriteScripts(List`1
scriptEntries, TextWriter outputWriter, Boolean enableCdn) at
AjaxControlToolkit.ToolkitScriptManagerCombiner.GetCombinedRegisteredScriptContent(Boolean
enableCdn) at
AjaxControlToolkit.ToolkitScriptManager.LoadScriptReferences(HttpContextBase
context, String[] bundles, Boolean forCombineAndMinify) at
AjaxControlToolkit.ToolkitScriptManager.OnLoad(EventArgs e) at
System.Web.UI.Control.LoadRecursive() at
System.Web.UI.Control.LoadRecursive() at
System.Web.UI.Control.LoadRecursive() at
System.Web.UI.Control.LoadRecursive() at
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Stack Trace:
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at
System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)Occured onSystem.Web - Boolean
HandleError(System.Exception) Inner Exception-->
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at AjaxControlToolkit.ToolkitScriptManagerHelper.GetAssembly(String name)
at AjaxControlToolkit.ToolkitScriptManagerCombiner.IsScriptCombinable(ScriptEntry
scriptEntry, Boolean enableCdn)
at AjaxControlToolkit.ToolkitScriptManagerCombiner.WriteScripts(List`1
scriptEntries, TextWriter outputWriter, Boolean enableCdn)
at AjaxControlToolkit.ToolkitScriptManagerCombiner.GetCombinedRegisteredScriptContent(Boolean
enableCdn)
at AjaxControlToolkit.ToolkitScriptManager.LoadScriptReferences(HttpContextBase
context, String[] bundles, Boolean forCombineAndMinify)
at AjaxControlToolkit.ToolkitScriptManager.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
You are registering scripts with the same key (name). Check ScriptManager <Scripts> section, and all RegisterClientScriptBlock and RegisterStartupScript calls for duplicates.
Also use IsClientScriptBlockRegistered and IsStartupScriptRegistered before registering any scripts to avoid that in the future.

Handle exception inside Application_Error global.asax

I have code written in global file on Application_Error.
I am inserting the error detail in my database.
But some how sometimes it is inserting thousand record of same error.
Does this mean that there is an error inside Application_Error
If yes then how can I handle that.
Edit 1
I am also redirecting to error page after inserting the error.
Error detail
Message: Exception of type 'System.Web.HttpUnhandledException' was thrown.<br><br><br>
Inner Exception : System.NullReferenceException: Object reference not set to an instance of an object.
at System.Collections.Specialized.NameObjectCollectionBase.BaseGetKey(Int32 index)
at System.Collections.Specialized.NameObjectCollectionBase.BaseRemove(String name)
at System.Web.SessionState.SessionStateItemCollection.Remove(String name)
at InfoDomeWeb.UserControl.LeftPanel.SetCustomerInfo() in D:\Working Folder\InfoDome\InfoDomeWeb\UserControl\LeftPanel.ascx.cs:line 185
at InfoDomeWeb.UserControl.LeftPanel.Page_Load(Object sender, EventArgs e) in D:\Working Folder\InfoDome\InfoDomeWeb\UserControl\LeftPanel.ascx.cs:line 71
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)<br><br><br>Stack trace: at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.error_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\961a93aa\98c42fe5\App_Web_304di5zu.12.cs:line 0
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
The error occurred on the page
D:\Working Folder\InfoDome\InfoDomeWeb\UserControl\LeftPanel.ascx.cs
But I don't find any thing wrong there.

ArgumentException: Unterminated string passed in

I recently encountered this error in one of the pages in my site.
[ArgumentException: Unterminated string passed in. (26): {"selectedIndexes":["0"],"]
at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeString()
at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeMemberName()
at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeDictionary(Int32\ depth)
at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32\ depth)
at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String\ input, Int32 depthLimit, JavaScriptSerializer serializer)
at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer\ serializer, String input, Type type, Int32 depthLimit)
at System.Web.Script.Serialization.JavaScriptSerializer.DeserializeObject(String\ input)
at Telerik.Web.UI.RadCompositeDataBoundControl.LoadPostData(String postDataKey,\ NameValueCollection postCollection)
at Telerik.Web.UI.RadCompositeDataBoundControl.System.Web.UI.IPostBackDataHandler.LoadPostData(String\ postDataKey, NameValueCollection postCollection)
at System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean\ fBeforeLoad)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,\ Boolean includeStagesAfterAsyncPoint)
[HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown.]
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,\ Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint,\ Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.pages_appeal_appealaction_aspx.ProcessRequest(HttpContext context)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
What could be the reason for this exception ? Any ideas how to solve it ??
Yep. This error happens when the ASP.NET system receives a request, routes it to your handler and ModelBinder takes over to map values passed in to parameters in your handler. When one of those parms is a string and that string is started but not terminated, it throws the System.ArgumentException from the System.String.DeserializeString() method.
You have two options.
Fix the string data on the browser in JavaScript before you send it. (duh).
Create a custom Model Binder to handle the exception gracefully and send back a 500-series HTTP error or better yet, fix the data in a predictable way. That fixing is not always possible like in a sound file, image, movie or other base64-encoded blob.
Here's how to do #2 - Creating a custom model binder.

DotNetZip FileIOPermission - can't add files to zip, though I have rights

I completely fail to get dotnetzip to add files to a .zip file
i can:
using (ZipFile zip = new ZipFile())
{
zip.AddEntry("test.txt", DateTime.Now.ToString());
zip.Save(Response.OutputStream);
}
This is completed correctly and produces a zip file for download that can be opned with the text file inside
Problem: Trying to add files like this:
zip.AddFile(Server.MapPath("/Files/test.txt"), "Files");
Always result in something like this:
[SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
System.Security.CodeAccessPermission.Demand() +61
System.IO.File.GetLastWriteTimeUtc(String path) +114
System.IO.File.GetLastWriteTime(String path) +24
Ionic.Zip.ZipEntry.Create(String nameInArchive, ZipEntrySource source, Object arg1, Object arg2) in c:\DotNetZip\Zip\ZipEntry.cs:2405
Ionic.Zip.ZipEntry.CreateFromFile(String filename, String nameInArchive) in c:\DotNetZip\Zip\ZipEntry.cs:2313
Ionic.Zip.ZipFile.AddFile(String fileName, String directoryPathInArchive) in c:\DotNetZip\Zip\ZipFile.AddUpdate.cs:406
Ionic.Zip.ZipFile.AddFile(String fileName) in c:\DotNetZip\Zip\ZipFile.AddUpdate.cs:296
MultiFileDownloader.WebForm1.Button1_Click(Object sender, EventArgs e) in D:\WORK\dynamicweb\StandardModules\MultiFileDownloader\Source\MultiFileDownloader\WebForm1.aspx.cs:54
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6785
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +242
System.Web.UI.Page.ProcessRequest() +80
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
System.Web.UI.Page.ProcessRequest(HttpContext context) +49
ASP.webform1_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\ade7bc1a\c2b11481\App_Web_txhzteca.0.cs:0
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
Note: My code can read/create the files with no problem. IIS user (and everyone infact) have total permissions to the files in question. IIS 7.5, win2008r2
How can I grant the DotNetZip assembly the same rights?
Figured it out my self:
On application pool I set the Load User profile to true....problem solved. Guess the assembly was running without any user at all (not everyone, not anomnynous, not no one)

Resources