Browser refresh error in ASP.NET - asp.net

I am developing an application in asp.net 2.0.
In one form i have a button, and on click which will insert data into database.
now after inserting if i click bowser refresh button i am getting the following error.
Refresh detected 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.Web.HttpException: Refresh detected
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:
[HttpException (0x80004005): Refresh detected]
WebTemplate.Template.RefreshProtectModule.appl_AcquireRequestState(Object
source, EventArgs e) +351
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
+68 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
Thanks in advance..

Hitting refresh is actually the same as clicking the button to insert data again. Your button click event should probably redirect the user to a new page.

Apparently you're using something called "RefreshProtectModule" which does not allow refresh. On one hand that's good - otherwise your form would insert record into DB on every refresh. On the other - you have to handle the "Refresh detected" exception and handle it graciously.

Related

InvalidOperationException occurs when I implement authentication

I tried to test a web page with authentication. The login page was fine, but after login, no matter authenticated successfully or not, an error with such message appeared:
Server Error in '/' Application.
Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.
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.InvalidOperationException: Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.
Stack Trace:
[InvalidOperationException: Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.]
System.Windows.Forms.MessageBox.ShowCore(IWin32Window owner, String text, String caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, Boolean showHelp) +1094
Microsoft.VisualBasic.Interaction.MsgBox(Object Prompt, MsgBoxStyle Buttons, Object Title) +310
XXX.Login.LoginUser_Authenticate(Object sender, AuthenticateEventArgs e) in "a path that is not in the testing server"\Login.aspx.vb:56
System.Web.UI.WebControls.Login.AttemptLogin() +144
System.Web.UI.WebControls.Login.OnBubbleEvent(Object source, EventArgs e) +107
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5028```
(Development and testing of the web page are done in different remote connections, but that path is actually in the development server.)
Even after I commented out the method Protected Sub LoginUser_Authenticate(ByVal sender As Object, ByVal e As AuthenticateEventArgs), such exception still occurred, unless I take away OnAuthenticate="LoginUser_Authenticate" from <asp:Login>(another exception occurs though).
Anyone knows what's the reason of the occurrence of such exception? I have totally no idea about the content in the stack trace.

Orchard signalr CryptographicException

I got this exception with Orchard with SignalR 1.3.1 chat module deploed on IIS on windows server 2008. It works fine in debug environment.
The data protection operation was unsuccessful. This may have been caused by not having the user profile loaded for the current thread's user context, which may be the case when the thread is impersonating.
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.Security.Cryptography.CryptographicException: The data protection operation was unsuccessful. This may have been caused by not having the user profile loaded for the current thread's user context, which may be the case when the thread is impersonating.
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.
[CryptographicException: The data protection operation was unsuccessful. This may have been caused by not having the user profile loaded for the current thread's user context, which may be the case when the thread is impersonating.]
Microsoft.Owin.Host.SystemWeb.Infrastructure.<>c__DisplayClass1.<GetRethrowWithNoStackLossDelegate>b__0(Exception ex) +42
Microsoft.Owin.Host.SystemWeb.CallContextAsyncResult.End(IAsyncResult result) +88
Orchard.Mvc.Routes.HttpAsyncHandler.EndProcessRequest(IAsyncResult result) +42
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288
The solution of same problem is described here, but I can not figure out how to apply it to the Orchard
Thanks in advance
Module has a bug.
You can fix this by adding to CoreModule.cs in Load(ContainerBuilder moduleBuilder) method line:
moduleBuilder.RegisterType<MachineKeyProtectedData>()
.As<IProtectedData>();

CryptographicException ID1073 error The is invalid on ASP.NET 4.0 site

Has anyone ever come across this error? I'm getting this when I post back to a forms authenticated site after redirecting to another site and then redirecting back. I've already checked that loadUserProfiles="true" but that did not help. This is a site hosted on IISExpress via other sites also hosted on IISExpress, using localhost gen'ed SSL certs and differentiating via host header. I'm pretty clueless at this point on where the error even comes from. Is it a cookie error? The FormsAuth cookie? It's ASP.NET 4.0 site where I'm authenticating against a Thinktecture Id server. Any feedback is appreciated to help me with my current block. Thanks
Server Error in '/' Application.
The data is invalid.
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.Security.Cryptography.CryptographicException: The data is invalid.
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:
[CryptographicException: The data is invalid.
]
System.Security.Cryptography.ProtectedData.Unprotect(Byte[] encryptedData, Byte[] optionalEntropy, DataProtectionScope scope) +318
Microsoft.IdentityModel.Web.ProtectedDataCookieTransform.Decode(Byte[] encoded) +203
[InvalidOperationException: ID1073: A CryptographicException occurred when attempting to decrypt the cookie using the ProtectedData API (see inner exception for details). If you are using IIS 7.5, this could be due to the loadUserProfile setting on the Application Pool being set to false. ]
Microsoft.IdentityModel.Web.ProtectedDataCookieTransform.Decode(Byte[] encoded) +319
Microsoft.IdentityModel.Tokens.SessionSecurityTokenHandler.ApplyTransforms(Byte[] cookie, Boolean outbound) +217
Microsoft.IdentityModel.Tokens.SessionSecurityTokenHandler.ReadToken(XmlReader reader, SecurityTokenResolver tokenResolver) +1951
Microsoft.IdentityModel.Tokens.SessionSecurityTokenHandler.ReadToken(Byte[] token, SecurityTokenResolver tokenResolver) +149
Microsoft.IdentityModel.Web.SessionAuthenticationModule.ReadSessionTokenFromCookie(Byte[] sessionCookie) +595
Microsoft.IdentityModel.Web.SessionAuthenticationModule.TryReadSessionTokenFromCookie(SessionSecurityToken& sessionToken) +120
Microsoft.IdentityModel.Web.SessionAuthenticationModule.OnAuthenticateRequest(Object sender, EventArgs eventArgs) +113
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +136
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18044
Crypto errors like this are common if your application pool is not set to load its user profile. The crypto system needs to access user's cert store.
The exact moment the error occurs is when you authenticate and the sts sends back the signed SAML token.
This means that the error is subtle. You don't see it everytime, only in one exact moment. You can even be deceived that the error is gone because the site works correctly, however the error reappears as soon as someone tries to log in.
The problem was only happening in IE9 when running in Debug mode. After awhile it went away for whatever reason. :/

web api TaskScheduler.UnobservedTaskException

I have recently published an asp.net web api to a production web site. On production about once a day the an unhandled exception causes the web site process to recycle:
An unhandled exception occurred and the process was terminated.
Application ID: /LM/W3SVC/2/ROOT/oasis Process ID: 9236 Exception:
System.AggregateException Message: A Task's exception(s) were not
observed either by Waiting on the Task or accessing its Exception
property. As a result, the unobserved exception was rethrown by the
finalizer thread. StackTrace: at
System.Threading.Tasks.TaskExceptionHolder.Finalize() InnerException:
System.Web.HttpException Message: The remote host closed the
connection. The error code is 0x800704CD. StackTrace: at
System.Web.Http.WebHost.HttpControllerHandler.EndProcessRequest(IAsyncResult
result) at
System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
Boolean& completedSynchronously)
This exception appears to not to originate in program code but in web api internals. I need to prevent such an excetion from recycling the process as this destroys the sessions of numberous users.
I understand that one way to handle this exception is to use :
TaskScheduler.UnobservedTaskException += (sender, e) =>
{
McpsEventLog.PostException(e.Exception, "webapicontroller");
e.SetObserved();
};
But for this to work, where can I put this code. somewhere in the web api controller? Or in the global.asax. Does someone know how the UnobserveredTaskException can be impletmented in an asp.net Web Api rest service?
You are right: Unhandled exception are unacceptable in the context of a web application. The right place to setup that handler is the Application_Start event.
You also should set up UnhandledException-event. It does not allow you to swallow the exception, though. Only log it.
Finally, see my question about this topic: How to treat unhandled thread-exceptions in ASP.NET? I did not get a usable answer but it might still help you.

The HTTP verb POST used to access path '/' is not allowed

The entire error:
Server Error in '/' Application.
The HTTP verb POST used to access path '/' is not allowed.
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.Web.HttpException: The HTTP verb POST used to access
path '/' is not allowed.
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:
[HttpException (0x80004005): The HTTP verb POST used to access path '/' is not allowed.]
System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state) +2871966
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8679410
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
To be honest, I'm not even sure where the error came from. I'm running Visual Studio 2008 through the Virtual Server. I just put a button:
<asp:Button ID="btnRegister" runat="server" Text="Register"
CssClass="bt_register" onclick="btnRegister_Click" />
On a login user control, the onclick event is just a simple response.redirect
Response.Redirect("~/register.aspx");
Debugging the project, it isn't even hitting the btnRegister_Click method anyway. I'm not sure where to even begin with debugging this error. Any information will help. I can post all the code I have, but like I said, I'm not sure where this error is even being thrown at.
Edit
It has nothing at all to do with the button click event. I got rid of the method and the onclick parameter on the aspx page. Still coming up with the same error
problem found
Okay so this is for a school project and its a group project. Some one in my group thought it would be a good idea to wrap a form tag around this area telling it to post. Found it doing a diff with a revision on Google code.
Are you rewriting URLs?
it seems that there are problems with the url rewriting.
http://www.lukemelia.com/blog/archives/2007/01/05/aspnet-the-http-verb-post-used-to-access-path-is-not-allowed/
You have to remove the mapping of ‘*’ to aspnet_isapi.dll in yourIIS settings.
While a Canvas URL value has to end in "/", the Tabl URL can be a fully qualified page (e.g. http://[DOMAIN/DIRECTORY-PATH]/Default.aspx).
I'm working locally, so http://localhost:4604/Main/Default.aspx worked for me.

Resources