Page_Init() being called twice - asp.net

The Page_Init() method of my page is being called twice before it is first displayed. In both cases, IsPostBack==false. I have AutoEventWireup="true" set. Here are the two stack traces for when it's being called:
First call:
G2.dll!Ctron.UI.Common.BreakoutDialog.Page_Init(object sender, System.EventArgs e) Line 46 C#
System.Web.dll!System.Web.Util.CalliEventHandlerDelegateProxy.Callback(object sender, System.EventArgs e) Unknown
System.Web.dll!System.Web.UI.Control.OnInit(System.EventArgs e) Unknown
System.Web.dll!System.Web.UI.Page.OnInit(System.EventArgs e) Unknown
CXGlobal.dll!Ctron.UI.CtronDialog.OnInit(System.EventArgs e) Line 27 C#
System.Web.dll!System.Web.UI.Control.InitRecursive(System.Web.UI.Control namingContainer) Unknown
System.Web.dll!System.Web.UI.Page.ProcessRequestMain(bool includeStagesBeforeAsyncPoint, bool includeStagesAfterAsyncPoint) Unknown
System.Web.dll!System.Web.UI.Page.ProcessRequest(bool includeStagesBeforeAsyncPoint, bool includeStagesAfterAsyncPoint) Unknown
System.Web.dll!System.Web.UI.Page.ProcessRequest() Unknown
System.Web.dll!System.Web.UI.Page.ProcessRequestWithNoAssert(System.Web.HttpContext context) Unknown
System.Web.dll!System.Web.UI.Page.ProcessRequest(System.Web.HttpContext context) Unknown
App_Web_g2ej3jrk.dll!ASP.common_breakoutdialog_aspx.ProcessRequest(System.Web.HttpContext context) C#
System.Web.dll!System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() Unknown
System.Web.dll!System.Web.HttpApplication.ExecuteStep(System.Web.HttpApplication.IExecutionStep step, ref bool completedSynchronously) Unknown
System.Web.dll!System.Web.HttpApplication.ApplicationStepManager.ResumeSteps(System.Exception error) Unknown
System.Web.dll!System.Web.HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(System.Web.HttpContext context, System.AsyncCallback cb, object extraData) Unknown
System.Web.dll!System.Web.HttpRuntime.ProcessRequestInternal(System.Web.HttpWorkerRequest wr) Unknown
System.Web.dll!System.Web.HttpRuntime.ProcessRequestNoDemand(System.Web.HttpWorkerRequest wr) Unknown
System.Web.dll!System.Web.Hosting.ISAPIRuntime.ProcessRequest(System.IntPtr ecb, int iWRType) Unknown
System.Web.dll!System.Web.Hosting.ISAPIRuntime.System.Web.Hosting.IISAPIRuntime2.ProcessRequest(System.IntPtr ecb, int iWRType) Unknown
[AppDomain Transition]
Second call:
G2.dll!Ctron.UI.Common.BreakoutDialog.Page_Init(object sender, System.EventArgs e) Line 46 C#
System.Web.dll!System.Web.Util.CalliEventHandlerDelegateProxy.Callback(object sender, System.EventArgs e) Unknown
System.Web.dll!System.Web.UI.Control.OnInit(System.EventArgs e) Unknown
System.Web.dll!System.Web.UI.Page.OnInit(System.EventArgs e) Unknown
CXGlobal.dll!Ctron.UI.CtronDialog.OnInit(System.EventArgs e) Line 27 C#
System.Web.dll!System.Web.UI.Control.InitRecursive(System.Web.UI.Control namingContainer) Unknown
System.Web.dll!System.Web.UI.Page.ProcessRequestMain(bool includeStagesBeforeAsyncPoint, bool includeStagesAfterAsyncPoint) Unknown
System.Web.dll!System.Web.UI.Page.ProcessRequest(bool includeStagesBeforeAsyncPoint, bool includeStagesAfterAsyncPoint) Unknown
System.Web.dll!System.Web.UI.Page.ProcessRequest() Unknown
System.Web.dll!System.Web.UI.Page.ProcessRequestWithNoAssert(System.Web.HttpContext context) Unknown
System.Web.dll!System.Web.UI.Page.ProcessRequest(System.Web.HttpContext context) Unknown
App_Web_g2ej3jrk.dll!ASP.common_breakoutdialog_aspx.ProcessRequest(System.Web.HttpContext context) C#
System.Web.dll!System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() Unknown
System.Web.dll!System.Web.HttpApplication.ExecuteStep(System.Web.HttpApplication.IExecutionStep step, ref bool completedSynchronously) Unknown
System.Web.dll!System.Web.HttpApplication.ApplicationStepManager.ResumeSteps(System.Exception error) Unknown
System.Web.dll!System.Web.HttpApplication.ResumeStepsFromThreadPoolThread(System.Exception error) Unknown
System.Web.dll!System.Web.HttpApplication.AsyncEventExecutionStep.OnAsyncEventCompletion(System.IAsyncResult ar) Unknown
System.Web.dll!System.Web.HttpAsyncResult.Complete(bool synchronous, object result, System.Exception error, System.Web.RequestNotificationStatus status) Unknown
System.Web.dll!System.Web.SessionState.SessionStateModule.PollLockedSessionCallback(object state) Unknown
mscorlib.dll!System.Threading.TimerQueueTimer.CallCallbackInContext(object state) Unknown
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Unknown
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Unknown
mscorlib.dll!System.Threading.TimerQueueTimer.CallCallback() Unknown
mscorlib.dll!System.Threading.TimerQueueTimer.Fire() Unknown
mscorlib.dll!System.Threading.TimerQueue.FireNextTimers() Unknown
mscorlib.dll!System.Threading.TimerQueue.AppDomainTimerCallback() Unknown
[Native to Managed Transition]
The difference happens at the point where System.Web.HttpApplication.ResumeStepsFromThreadPoolThread() calls ResumeSteps() again and that eventually calls Page_Init() again.

Two things that have caused this to happen to me;
You have a blank src element in a HTML image tag that effectively makes another request to the same page. For example,
Two lots of events wired up. In VB this happens when you have an explicit handles clause on a method and it is also wired up via the designer. You might prefer to wire up your events explicitly and turn off auto event wireup (this goes for C# too).
It could be many things, but the img tag happens a lot.

Related

Specified cast is not valid. ASP Radiobutton

I am getting the following error:
Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Specified cast is not valid.
Code:
<asp:RadioButtonList ID="rbtVerified" runat="server" Visible='<%#!(bool)Eval("ReadOnly") %>' >
<asp:ListItem Value="1">Accept</asp:ListItem>
<asp:ListItem Value="2">Reject</asp:ListItem>
</asp:RadioButtonList>
Value ReadOnly is being retrieved successfully from the database and it is bool (saved as bit in sql server. What exactly could the problem be?
Exception is also being thrown here when trying to bind the data (Note: bool testis just a test to check if variable ReadOnly being retrieved properly from the database.
DataTable dt = new LeaveLogic().GetManagerUnverifiedLeaveRequests(Convert.ToInt32(Context.User.Identity.Name));
if (dt.Rows.Count > 0)
{
bool test = Convert.ToBoolean(dt.Rows[0]["ReadOnly"]);
RptLeaveRequests.DataSource = dt;
RptLeaveRequests.DataBind();
}
More detaield error:
System.InvalidCastException was unhandled by user code
HResult=-2147467262
Message=Specified cast is not valid.
Source=App_Web_kdnthep4
StackTrace:
at ASP.webpages_verifyleaverequests_aspx.__DataBinding__control43(Object sender, EventArgs e) in c:\Users\Samsung\Desktop\Development\Ticketing system\1.PresentationLayer\WebPages\VerifyLeaveRequests.aspx:line 35
at System.Web.UI.Control.OnDataBinding(EventArgs e)
at System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e)
at System.Web.UI.WebControls.ListControl.PerformSelect()
at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
at System.Web.UI.Control.DataBindChildren()
at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
at System.Web.UI.Control.DataBind()
at System.Web.UI.Control.DataBindChildren()
at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
at System.Web.UI.Control.DataBind()
at System.Web.UI.Control.DataBindChildren()
at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
at System.Web.UI.Control.DataBind()
at System.Web.UI.Control.DataBindChildren()
at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
at System.Web.UI.Control.DataBind()
at System.Web.UI.WebControls.Repeater.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem)
at System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource)
at System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e)
at System.Web.UI.WebControls.Repeater.DataBind()
at _1.PresentationLayer.WebPages.VerifyLeaveRequests.BindData() in C:\Users\Samsung\Desktop\Development\Ticketing system\1.PresentationLayer\WebPages\VerifyLeaveRequests.aspx.cs:line 58
at _1.PresentationLayer.WebPages.VerifyLeaveRequests.Page_Load(Object sender, EventArgs e) in C:\Users\Samsung\Desktop\Development\Ticketing system\1.PresentationLayer\WebPages\VerifyLeaveRequests.aspx.cs:line 24
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:

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.

Yahoo, OAuth http request. Works on localhost but not live server

I have this code that is trying to authenticate with Yahoo! It works fine on my local sever but the same request made on my live server fails. It comes back with a (401) Unauthorized error when it calls GetResponse(). Can anyone help me understand why? Let me know if you need more information.
try
{
string url = "https://api.login.yahoo.com/oauth/v2/get_request_token?oauth_callback=" + Server.UrlEncode("http://www.dowdlefolkart.com/extensions/contacts/webform1.aspx");
url = GetUrl(url, consumerKey, consumerSecret);
var req = System.Net.HttpWebRequest.Create(url);
using (var res = req.GetResponse().GetResponseStream())
{
....
}
}
catch (Exception ex)
{
Response.Write("ERROR" + ex.Message);
}
Here is the full Error Exception:
System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.Net.WebException: The remote server returned an error: (401) Unauthorized.
at System.Net.HttpWebRequest.GetResponse()
at NopSolutions.NopCommerce.Web.Extensions.Contacts.WebForm1.Page_Load(Object sender, EventArgs e)
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
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.extensions_contacts_webform1_aspx.ProcessRequest(HttpContext context)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Update:
I am getting this error with Fiddler.
oauth_problem=timestamp_refused&oauth_acceptable_timestamps=1314119105-1314120305
So it looks like my timestamp from the live server is not correct. This is how I am creating the timestamp:
string timestamp = Math.Floor((DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds).ToString();
I found the issue. The reason for the error was due to an invalid timestamp. It was just slightly larger than that which was allowed. Using Fiddler i was able to determine this issue. The error was: oauth_problem=timestamp_refused&oauth_acceptable_timestamps=1314119105-1314120305.
I then logged onto my live server and adjusted the system clock to what it needed to be. Apparently it was 15 minutes fast. Once I adjusted this the error disappeared. Thank you #Darin Dimitrov for the assistance.

Handle "Cannot access a closed resource set"

I have a website with several languages in a database. From the database I use ResXResourceWriter to create my .resx files. This is working really good but sometimes I get this exception:
MESSAGE: Cannot access a closed resource set.
SOURCE: mscorlib
FORM:
QUERYSTRING:
TARGETSITE: System.Object GetObject(System.String, Boolean, Boolean)
STACKTRACE: at System.Resources.RuntimeResourceSet.GetObject(String key, Boolean ignoreCase, Boolean isString)
at System.Resources.RuntimeResourceSet.GetString(String key, Boolean ignoreCase)
at System.Resources.ResourceManager.GetString(String name, CultureInfo culture)
at System.Linq.Expressions.Expression.ValidateStaticOrInstanceMethod(Expression instance, MethodInfo method)
at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, IEnumerable`1 arguments)
at System.Data.Linq.DataContext.GetMethodCall(Object instance, MethodInfo methodInfo, Object[] parameters)
at System.Data.Linq.DataContext.ExecuteMethodCall(Object instance, MethodInfo methodInfo, Object[] parameters)
at Business.DatabaseModelDataContext.Web_GetMostPlayedEvents(String cultureCode)
at Presentation.Default.Page_Load(Object sender, EventArgs e)
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
I don't know why this is happening or how to solve it. Does anyone know anything about this?
Thanks,
Philip
I suspect you closed your DataSource prematurely or didn't close it at all when your program routine is about to end?

NullReferenceException when running published website in IIS

I have a website that I published before adding it in IIS. After that I set the published website as the default website in IIS.
I got an error that the "Object reference is not set to the instance of an object" when I inserted values through form. There is no issues when the website is running in IIS without publishing. The error occurs when values are inserted using datagrid.
The error messages is as follows:
Server Error in '/' Application.
Object reference not set to an
instance of an object.
Description: An unhandled exception
occurred during the execution of the
current web request. Please review the
stack trace for more information about
the error and where it originated in
the code.
Exception Details:
System.NullReferenceException: Object
reference not set to an instance of an
object.
Source Error:
An unhandled exception was generated
during the execution of the current
web request. Information regarding the
origin and location of the exception
can be identified using the exception
stack trace below.
Stack Trace:
[NullReferenceException: Object
reference not set to an instance of an
object.]
Admin_MasterEntries.gvwMileStoneM_RowCommand(Object
sender, GridViewCommandEventArgs e)
+447 System.Web.UI.WebControls.GridView.OnRowCommand(GridViewCommandEventArgs
e) +105
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs
e, Boolean causesValidation, String
validationGroup) +76
System.Web.UI.WebControls.GridView.OnBubbleEvent(Object
source, EventArgs e) +95
System.Web.UI.Control.RaiseBubbleEvent(Object
source, EventArgs args) +35
System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object
source, EventArgs e) +117
System.Web.UI.Control.RaiseBubbleEvent(Object
source, EventArgs args) +35
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs
e) +115
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String
eventArgument) +163
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
+11 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection
postData) +174
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean
includeStagesAfterAsyncPoint) +5102
If any one knows please help me. Thank you.
That exception is caused by an object not being instantiated. Open the project and attach a debugger to the IIS process. A web service which is consuming the ASP.NET page is throwing the exception.
Try this:
Click your site in IIS
Open Pages and Controls section
Find ViewState group and check if ViewState is enabled.
Such solution helped me to solve null reference exception problem after publish.

Resources