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:
- 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:
- Create a FormsAuthenticationTicket.
- Get the encrypt cookie string.
- Create a HTTP cookie.
- Add the cookie to the response cookie, so javascript can access this cookie.
- 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.
