The leading provider of version control solution and TWAIN SDK

How to upload image with Forms-Based Authentication in Your ASP.NET Application

In Dynamic Web TWAIN, we can use HTTPUploadThroughPost method to upload image to the server. But if you use Forms-Based Authentication in Your ASP.NET Application, you might not be able to upload the image successfully. Because the action page will verify the login information for the HTTP post request, and by default the HTTPUploadThroughPost will not pass the login information to the action page.

Error Message:
ErrorString - "HTTP process error".
HTTPPostResponseString - The whole HTML code of the login page.

You can follow below steps to fix this issue:

  1. Go to the login page, and make sure you have stored the login information in the HTTP cookie. At a later stage, we will pass the HTTP cookie to the action page for authentication.
              Example:
             

    1. Create a FormsAuthenticationTicket.
    2. Get the encrypt cookie string.
    3. Create a HTTP cookie.
    4. Add the cookie to the response cookie, so javascript can access this cookie.


  2. Go to the scan page, and add below code before you call HTTPUploadThroughPost method.

    WebTwain.SetCookie(document.cookie);

    Note: Please change ‘WebTwain’ according to your application.

    Thus, the cookie will be attached to the HTTP post request and the action page will use the cookie to verify the login information.

You can find the sample project in the attachment. Please use (User name: user1, Password: user1) to login to the application.

Please also NOTE that in the Web.Config file, the settings for Forms Authentification should look something like the below lines:

<authentication mode="Forms">
            <forms name="testform" loginUrl="login.aspx" domain="localhost" defaultUrl="default.aspx" path="/" timeout="2">
            </forms>
</authentication>

Especially, the "Domain" is necessary here.




Article Details

Last Updated
26th o April, 2012

Would you like to...

Print this page Print this page

Email this page Email this page

Post a comment Post a comment

Subscribe me

Add to favorites Add to favorites

Remove Highlighting Remove Highlighting

Edit this Article

Quick Edit

Export to PDF

User Opinions (0 votes)

No users have voted.

How would you rate this answer?



Thank you for rating this answer.

Related Articles

No related articles were found.

Attachments

Visitor Comments

  1. Comment #1 (Posted by Lathe)
    This method do not work, becouse Asp.Net Form Auth cookie has been marked a HttpOnly attribute and invisible for java script.
  2. Comment #2 (Posted by support )
    The method actually works. We do not use the form auth cookie directly. Instead, we created a HTTPCookie and added it to the HTTP response. Please let me know if you have any further questions.

Post a comment

To post a comment for this article, simply complete the form below. Fields marked with an asterisk are required.
   Name:
   Email:
* Comment:
* Enter the code below:
 

Continue