Error: Response is not available in this context.

Aug 31, 2008 at 7:29 PM
Edited Aug 31, 2008 at 7:30 PM
Hey everyone,

I'm trying to upload a document (either sync or async) and I keep getting the same error message: Response is not available in this context.

I've got to be missing something obvious, but I can't seem to find it.   Here's my code (everything is in the Page_Load of a asp.net app):

// Set up keys
        Scribd.Net.Service.APIKey = "apikey";
        Scribd.Net.Service.SecretKey = "secretkey";
        Scribd.Net.Service.EnforceSigning = true;
        //Scribd.Net.Service.PublisherID = "MyPublisherId";  // Optional

        // Sign into the service
        bool signInResult = Scribd.Net.User.Login("username", "password");

        if (signInResult)
            Response.Write("Sign in successful!");
        else
            Response.Write("Sign in failed");

        // Set up upload notification
        Scribd.Net.Document.Uploaded += new EventHandler<DocumentEventArgs>(Document_Uploaded);

        string path = "testfile.pdf";
        Response.Write(String.Format("<p>Saving {0}</p>", path));

        // Send our PDF document to Scribd.
        Scribd.Net.Document settings = Scribd.Net.Document.Upload(@"C:\Inetpub\Websites\ScribdTest\Website\testfile.pdf", Scribd.Net.AccessTypes.Private);
-----------------

The error is on the last line (the Upload call).  Here is the stack trace if it helps:

[HttpException (0x80004005): Response is not available in this context.]
System.Web.UI.Page.get_Response() +2073113
_Default.Document_Uploaded(Object sender, DocumentEventArgs e) +39
System.EventHandler`1.Invoke(Object sender, TEventArgs e) +0
Scribd.Net.Document.OnUploaded(Document document) +83
Scribd.Net.Document.Upload(String path, AccessTypes accessType, Int32 revisionNumber, String documentType) +789
Scribd.Net.Document.Upload(String path, AccessTypes accessType) +42
_UploadTest.Page_Load(Object sender, EventArgs e) in c:\Inetpub\Websites\ManageMyManuals\Website\UploadTest.aspx.cs:44
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
Thanks in advance!
Coordinator
Sep 1, 2008 at 5:21 AM
Edited Sep 1, 2008 at 5:29 AM
Hiya.  I'm not sure what I can do about this - this may relate to the way a page refreshes in ASP.NET.  I haven't really tested it in that environment.  The source code is, of course, available so perhaps you can resolve the issue by stepping through the code?  It may be that the Response object is on a different thread than the one trying to be accessed.

Try starting the upload on a different (background) thread.

I may be of more help if you put the entire code-behind here - not just the section of code.

- Paul