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

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.

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?

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.

asp.net application while deploying in IIS7 server error - cannot find table 0

I tried deploying an ASP.NET application in IIS server 7. I am using Windows 7. While deploying i am getting the error "Cannot find table 0."
Exception Details: System.IndexOutOfRangeException: Cannot find table 0
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:
[IndexOutOfRangeException: Cannot find table 0.]
System.Data.DataTableCollection.get_Item(Int32 index) +95
LHS.RightColumn.Page_Load(Object sender, EventArgs e) in C:\Saravanan\Saravanan\Saravanan\LHS\LHS\RightColumn.ascx.cs:33
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Control.LoadRecursive() +146
System.Web.UI.Control.LoadRecursive() +146
System.Web.UI.Control.LoadRecursive() +146
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
Please help me how to resolve this.
In Visual Studio this application is running fine.
But in IIS it is showing this error.
Please help me in this
I had this error some weeks back and it occurred because the web.config file was incorrect. The database information was invalid. Hopefully, this will help you.

ASP.NET + NetworkCredentials, The logon attempt failed

I've got an ASP.NET app that requires Windows Integrated Security.
For some reason, I don't what to discuss that here, I need to create a WebRequest at runtime, call some other page in the app and process the result.
The application runs on a server for which we use a DNS alias, something like theapp.domain.com.
So I create a NetworkCredential with a predefined domain user and password and I attach it to the request.
This is what I get:
[Win32Exception (0x80004005): The logon attempt failed]
System.Net.NTAuthentication.GetOutgoingBlob(Byte[] incomingBlob, Boolean throwOnError, SecurityStatus& statusCode) +1404402
System.Net.NTAuthentication.GetOutgoingBlob(String incomingBlob) +78
System.Net.NegotiateClient.DoAuthenticate(String challenge, WebRequest webRequest, ICredentials credentials, Boolean preAuthenticate) +560
System.Net.NegotiateClient.Authenticate(String challenge, WebRequest webRequest, ICredentials credentials) +14
System.Net.AuthenticationManager.Authenticate(String challenge, WebRequest request, ICredentials credentials) +247
System.Net.AuthenticationState.AttemptAuthenticate(HttpWebRequest httpWebRequest, ICredentials authInfo) +243
System.Net.HttpWebRequest.CheckResubmitForAuth() +232
System.Net.HttpWebRequest.CheckResubmit(Exception& e) +5299747
[WebException: The remote server returned an error: (401) Unauthorized.]
System.Net.HttpWebRequest.GetResponse() +5313085
Entropy.Envoy.Web.Corporate.ExportFilter.GetTargetReportContent(Uri targetUrl, HttpCookieCollection cookies) +521
Entropy.Envoy.Web.Corporate.ExportFilter.Page_Load(Object sender, EventArgs e) +139
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
The same code works on other servers with similar setup though.
What is going on?
Found the answer to this one.
Turned out to be as simple as adding an SPN to Active Directory like so:
setspn -a HTTP//WebServer.domain.com customDomainAccount
setspn -a HTTP//servername customDomainAccount

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