paypal nvp .net sdk error - asp.net

Folks,
We have a web site that uses PayPal Express Checkout for Digital Goods to make software sales. It has been working fine for 5 months. Last week we started getting an error "The request was aborted: Could not create SSL/TLS secure channel.” off the live site. When I run the site off my development server it runs fine and we can process a transaction. All these are against the live paypal site. In looking at many questions on this forum and others the main problem appears to be using the wrong endpoints. I am using the .NET SDK and the nvp methods. I checked the endpoints and they are the current ones provided by paypal for nvp transactions. Even looked in the dll to make sure we did't have an older version. We are good there.
Then I thought it might be that the hosting server could'd establish a secure link to paypal so created a test page with a url with query string to the endpoint like(https://api-3t.paypal.com/nvp?USER=XXXX_api1.XXX.com&PWD=XXX&SIGNATURE=XXXXXX&VERSION=60.0&PAYMENTACTION=Authorization&AMT=1.95&RETURNURL=https://www.paypal.com&CANCELURL=https://www.paypal.com&METHOD=SetExpressCheckout).
This worked and returned the expected transaction token. So we can connect from the hosting server. Then thinking our credentials or credential retrieval code might be the problem I pulled the credentials out of our database and ran the test as follows.
Test Query string with server data code======================================
This worked so credentials and endpoint are good on the hosting server.
( Dim sCEnvironment As String = System.Configuration.ConfigurationManager.AppSettings("Environment")
Dim dtsettings As DataTable
dtsettings = Dac.ExecuteDataTable("GetCredentials", Dac.Parameter("#Environment", sCEnvironment))
'// Set up your API credentials, PayPal end point, API operation and version.
Dim sAPIUsername As String = dtsettings.Rows(0).Item("UserName").ToString
Dim sAPISignature As String = dtsettings.Rows(0).Item("Signature").ToString
Dim sAPIPassword As String = dtsettings.Rows(0).Item("Password").ToString
Dim sEnvironment As String = dtsettings.Rows(0).Item("Environment").ToString
Dim QS As String = "https://api-3t.paypal.com/nvp?USER=" & sAPIUsername & "&PWD=" & sAPIPassword & "&SIGNATURE=" & sAPISignature & "&VERSION=60.0&PAYMENTACTION=Authorization&AMT=1.95&RETURNURL=https://www.paypal.com&CANCELURL=https://www.paypal.com&METHOD=SetExpressCheckout"
Response.Redirect(QS)
I then moved on to testing the token generation using the sdk dll (paypal_base.dll). See code below. As each line is generated I added to it a string that writes out to the test page so I can get an idea what is going on our hosting server. We use the express checkout for Digital Goods process. I got the basic code from https://cms.paypal.com/cms_content/FR/fr_FR/files/developer/nvp_DoAuthorization_cs.txt and added the Digital Goods query parameters per the online documentation. This works on my development server and returns the Token. It worked on the hosting site for about four months until sometime between January 27 and January 30 when I got the first notification that a customer could not purchase a product.
When run on our hosting server we get the “The request was aborted: Could not create SSL/TLS secure channel.” error message on the line of code highlighted below. The query string is generated by the encoder and held in the variable pStrrequestforNvp so the encoder works.
I am at a loss. What could be different on the hosting server than on our development server? Is there a method in the dll I could use to write out the actual call to the paypal server? I put the same dll file we used in development on the hosting site, but something is different.
Test the sdk generated query ===========================
Dim caller As NVPCallerServices = New NVPCallerServices
Dim profile As IAPIProfile = ProfileFactory.createSignatureAPIProfile
Dim sCEnvironment As String = System.Configuration.ConfigurationManager.AppSettings("Environment")
Dim dtsettings As DataTable
Dim sMsg As String
dtsettings = Dac.ExecuteDataTable("GetCredentials", Dac.Parameter("#Environment", sCEnvironment))
profile.APIUsername = dtsettings.Rows(0).Item("UserName").ToString
sMsg = "APIUserName = " & dtsettings.Rows(0).Item("UserName").ToString & "<br/>"
profile.APISignature = dtsettings.Rows(0).Item("Signature").ToString
sMsg = sMsg & "APISignature = " & dtsettings.Rows(0).Item("Signature").ToString & "<br/>"
profile.APIPassword = dtsettings.Rows(0).Item("Password").ToString
sMsg = sMsg & "APIPassword = " & dtsettings.Rows(0).Item("Password").ToString & "<br/>"
profile.Environment = dtsettings.Rows(0).Item("Environment").ToString
sMsg = sMsg & "Environment = " & dtsettings.Rows(0).Item("Environment").ToString & "<br/>"
caller.APIProfile = profile
Dim encoder As NVPCodec = New NVPCodec
encoder("VERSION") = "65.1"
encoder("METHOD") = "SetExpressCheckout"
encoder("RETURNURL") = "http://www.multiware.biz/return.aspx"
encoder("CANCELURL") = "http://www.multiware.biz/cancel.aspx"
encoder("PAYMENTREQUEST_0_CURRENCYCODE") = "USD"
encoder("PAYMENTREQUEST_0_PAYMENTACTION") = "Sale"
encoder("PAYMENTREQUEST_0_AMT") = "1.95"
encoder("PAYMENTREQUEST_0_ITEMAMT") = "1.95"
encoder("PAYMENTREQUEST_0_DESC") = "Software"
encoder("L_PAYMENTREQUEST_0_ITEMCATEGORY0") = "Digital"
encoder("L_PAYMENTREQUEST_0_NAME0") = "Test"
encoder("L_PAYMENTREQUEST_0_NUMBER0") = "123"
encoder("L_PAYMENTREQUEST_0_QTY0") = "1"
encoder("L_PAYMENTREQUEST_0_AMT0") = "1.95"
encoder("L_PAYMENTREQUEST_0_DESC0") = "Download"
encoder("REQCONFIRMSHIPPING") = "0"
encoder("NOSHIPPING") = "1"
encoder("SOLUTIONTYPE") = "Sole"
Try
Dim pStrrequestforNvp As String = encoder.Encode
sMsg = sMsg & "pStrrequestforNvp = " & pStrrequestforNvp & "<br/>"
Dim pStresponsenvp As String = caller.Call(pStrrequestforNvp) ***Error occurs here***
sMsg = sMsg & "pStresponsenvp = " & pStresponsenvp & "<br/>"
Dim decoder As NVPCodec = New NVPCodec
decoder.Decode(pStresponsenvp)
Dim Token As String = decoder("TOKEN")
sMsg = sMsg & "Token = " & Token & "<br/>"
Me.lblResponse.Text = sMsg.ToString
Catch ex As Exception
sMsg = sMsg & "<br/>" & ex.Message.ToString & "<br/>" _
& ex.StackTrace.ToString
Me.lblResponse.Text = sMsg.ToString
End Try

I'll answer my own question. After many back and forths with the web hosting service and PayPal we narrowed the problem to the Server not authorizing the Security Certificate. Had to put a trace on our page to find this and prove it was on their side. As I suspected it was an MS update that screwed things up. One day the site was working the next it wasn't.
For further reading on the subject see the dialog at http://forum.arvixe.com/smf/other-programs-promotions-graphics/need-urgent-help!-(paypal-checkout-not-working-any-more)/msg39498/#msg39498
To their credit the Arvixe folks tracked down the problem and eventually resolved it after we went back and forth a few times on whose problem it was.

Related

How to send multiple emails with ASP.NET VB.net

How do I set the code below to generate multiple emails like with a reminder every 15 minutes? Thank you for any guidance.
Private Sub SendEmail(ByVal pharmEmail As String, ByVal backupEmail As String)
Dim smtpClient As New System.Net.Mail.SmtpClient()
Dim message As New System.Net.Mail.MailMessage()
Try
Dim fromAddress As New System.Net.Mail.MailAddress(WebConfigurationManager.AppSettings("EmailFromAddr"), WebConfigurationManager.AppSettings("EmailFromName"))
message.From = fromAddress
message.To.Add(pharmEmail)
message.Subject = WebConfigurationManager.AppSettings("EmailSubject")
message.Priority = Net.Mail.MailPriority.High
If (WebConfigurationManager.AppSettings("backupEnabled") = True) Then
message.CC.Add(backupEmail)
End If
message.IsBodyHtml = True
Dim orderURL As New HyperLink
orderURL.Text = "here"
orderURL.NavigateUrl = "http://" & WebConfigurationManager.AppSettings("ServerName") & "/User/ReviewOrder.aspx?orderID=" & webOrderID
message.Body = "An order was created using the account of " + Profile.FirstName.ToString() + " " + Profile.LastName.ToString() + ". " + WebConfigurationManager.AppSettings("EmailBody") + "<a href='" + orderURL.NavigateUrl + "'>here.</a>"
'message.Body = WebConfigurationManager.AppSettings("EmailBody") & " " & orderURL.
smtpClient.Send(message)
Catch ex As Exception
ErrorHandler.WriteError(ex.ToString)
Throw ex
End Try
I agree with comments on the scheduler. If you don't like that you can create a windows service that does this. This will solve if you want to fire the routine every X minutes.
You don't have enough code here to send out emails, so you have to wrap this with some logic that fires the routine with the email information you want. More than likely, this is stored in a database (recipients, email) or some other persistent store.
I do caution the idea of sending reminders every 15 minutes to the same people, as you are more than likely to piss them off (unless that is your intent?).
Thank you all for you contributions. I have decided to create a SSIS package with a SQL and Send Email tasks. The SQL task check for new orders placed and the Send Email task sends reminder to users in a scheduled time.

VB.Net Outlook email creation works locally, fails on server

When I run my project on my local machine it generates the Outlook email as expected, but if I upload all my code to our development server, it fails with this error message when run: [Exception: Cannot create ActiveX component.]
Microsoft.VisualBasic.Interaction.CreateObject(String ProgId, String ServerName) +509721
etc...
I know it's the Outlook that's failing because if I comment the sendmail() function, the rest of the page works fine. (it just doesn't create the email).
Local machine is Windows 7 with Outlook installed, Server is 2008R2 with no Office installed. I have other pages that can write to Excel files, but they're using CrystalReports to handle it so I'm not sure if the server needs an Outlook dll registered, or if something else needs to happen.
Aspx page with a VB.Net codebehind. My create email looks like:
Dim OApp2 As Object, OMail2 As Object, signature2 As String
OApp2 = CreateObject("Outlook.Application")
OMail2 = OApp2.CreateItem(0)
Dim alAttachList As New ArrayList(2)
Dim iCounter As Integer
alAttachList.Insert(0, "E:\Test\DEBUG CODE.txt")
alAttachList.Insert(1, "\\RemoteServer\z\Test\Hello.bmp")
sBody += "<br />" + "Attached are some files." + "<br />" + "They can also be found in: X:\Test\Test\Name "
With OMail2
.Display()
End With
signature2 = OMail2.HTMLBody
With OMail2
.Subject = sSubject
.To = sTo
.CC = sCC
.HTMLbody = sBody & "<br /><br />" & signature2
End With
Dim sBodyLen As Integer = Int(sBody.Length)
Dim oAttachs2 As Interop.Outlook.Attachments = OMail2.Attachments
Dim oAttach2 As Interop.Outlook.Attachment
For iCounter = 0 To alAttachList.Count - 1
oAttach2 = oAttachs2.Add(Source:=alAttachList(iCounter), DisplayName:=alAttachList(iCounter))
Next
OMail2.Display(True)
OApp2 = Nothing
OMail2 = Nothing
When you do something like:
OApp2 = CreateObject("Outlook.Application")
You are using the Office.Interop libraries which are installed with MS Office (or the individual applications if you go that route)
You MUST install MS Office, or at least Outlook, on the server to use Office.Interop. You might look into using MAPI instead of interop to send your emails. MAPI is part of .Net and does NOT require additional programs be installed on your server.
Firstly, Outlook must be installed. Secondly, is your code running in a service (such as IIS)? No Office app (Outlook included) can be used from a service.

ASP.net This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms

Hey all i am getting this error when trying to compare a password in my database using my ASP.net page.
This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms.
The code looks like this:
Public Shared Function UserAuthentication(ByVal user As String, ByVal pass As String) As WebUserSession
Dim strSQL As String = ""
Dim strForEncryption As String = pass
Dim result As Byte()
Dim sHA1Managed As SHA1 = New SHA1Managed()
Dim encryptedString As New System.Text.StringBuilder()
result = sHA1Managed.ComputeHash(ASCIIEncoding.ASCII.GetBytes(pass))
For Each outputByte As Byte In result
'convert each byte to a Hexadecimal upper case string
encryptedString.Append(outputByte.ToString("x2").ToUpper())
Next
strSQL &= "SELECT email, name, id, permission_id, username FROM (user) INNER JOIN user_per ON user.id = user_per.user_id "
strSQL &= "WHERE(username = '" & user & "' And password = '" & encryptedString.ToString() & "')"
We recently had to update/lock down our server to be compliance with security holes and the like. But doing so caused this error for one of the websites we are hosting on the same server. Prior to all these security settings the web site worked just fine.
The odd part is that i am able to run the website local (debug mode) within VS 2010 and it does just fine. No errors at all.
Would anyone have any tips on how to go around this to make the website work again as it did before we added all these security settings to be complaint? We simply can not just disable it because that would cause our other websites to go out of compliance.
I've already tried the suggestions on these pages:
http://blogs.msdn.com/b/brijs/archive/2010/08/10/issue-getting-this-implementation-is-not-part-of-the-windows-platform-fips-validated-cryptographic-algorithms-exception-while-building-outlook-vsto-add-in-in-vs-2010.aspx
http://social.msdn.microsoft.com/Forums/en/clr/thread/7a62c936-b3cc-4493-a3cd-cc5fd18b6b2a
http://support.microsoft.com/kb/935434
http://blogs.iis.net/webtopics/archive/2009/07/20/parser-error-message-this-implementation-is-not-part-of-the-windows-platform-fips-validated-cryptographic-algorithms-when-net-page-has-debug-true.aspx
http://blog.aggregatedintelligence.com/2007/10/fips-validated-cryptographic-algorithms.html
Thanks.
Tried using this code as well
Dim p As String = Password.Text.ToString
Dim data(p) As Byte
Dim result() As Byte
Dim sha As New SHA1CryptoServiceProvider()
result = sha.ComputeHash(data)
The error is:
Conversion from string "S51998Dg5" to type 'Integer' is not valid.
And that error is on the line: Dim data(p) As Byte
According to this sha1managed is not fips compliant. It throws an InvalidOperationException because this class is not compliant with the FIPS algorithm.
You need to either disalbe FIPS compliance or use a FIPS compliant implementation. sha1cryptoserviceprovider I think is FIPS complaint.

Sharepoint not getting current user NetworkCredential from active directory

we have strange problem, we have single signon and we are trying to fetch unread email count from Exchange ews webservice, the problem is it always gets same count for all user which is actually for server user.
'it should now get for current user who requested the page
'but its always for server user where sharepoint is installed
Public Sub GetUnreadEmailCount()
Dim errormsg As String = String.Empty
Dim UnreadCount As Integer = 0
Dim esb As New ExchangeServiceBinding
Try
esb.RequestServerVersionValue = New RequestServerVersion
esb.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2007_SP1
esb.UseDefaultCredentials = True
esb.Url = Domain + "/EWS/Exchange.asmx"
ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf CertificateValidationCallBack)
Dim biArray(1) As BaseFolderIdType
Dim dfFolder As New DistinguishedFolderIdType
dfFolder.Id = DistinguishedFolderIdNameType.inbox
biArray(0) = dfFolder
Dim geGetFolder As New GetFolderType
geGetFolder.FolderIds = biArray
geGetFolder.FolderShape = New FolderResponseShapeType
geGetFolder.FolderShape.BaseShape = DefaultShapeNamesType.AllProperties
Dim gfResponse As GetFolderResponseType = esb.GetFolder(geGetFolder)
Dim rmta As ResponseMessageType() = gfResponse.ResponseMessages.Items
Dim rmt As FolderInfoResponseMessageType = DirectCast(rmta(0), FolderInfoResponseMessageType)
If rmt.ResponseClass = ResponseClassType.Success Then
Dim folder As FolderType = DirectCast(rmt.Folders(0), FolderType)
UnreadCount = folder.UnreadCount
End If
Label1.Text = vbCrLf + "Unread email count : " + UnreadCount.ToString
' Return UnreadCount
Catch ex As Exception
If Not ex.Message Is Nothing Then errormsg = ex.Message
Try
If Not ex.InnerException.Message Is Nothing Then errormsg = errormsg + " : " + ex.InnerException.Message
Catch e As Exception
End Try
Finally
If esb IsNot Nothing Then esb.Dispose() : esb = Nothing
If Not errormsg = String.Empty Then
Label1.Text = vbCrLf + "Error : " + errormsg
End If
End Try
End Sub
We were actually having the same problem, although we were not using single sign on. So I'm not sure this is exactly what you are experiencing.
The problem is that you can not have a user on Machine A give their credentials to Machine B (SharePoint?) and then have Machine B send those credentials on to Machine C
It's referred to as the "Double Hop" problem and is a security feature, however I'm not really into the technical side of it. Our solution was to use Kerberos.
I hope this helps you, if not, that it helps you rule out this specific issue :)
Your server side code is running as the AppPool's identity, which is your sharepoint service account. I'm assuming that's what you mean by 'the server user.'
esb.UseDefaultCredentials = true;
will use the creds of the context. I'm not sure of what's available in the EWS services, so if you can use a higher-privileged account and get based on the user coming in, i.e., HttpContext.Current.User.Identity as a parameter, then that may be the best way.
You could authenticate via javascript directly to the EWS services, skipping server-side code altogether, and write something that consumes & displays the server stuff as you need it.
You'd need to find a way to auth the user directly to the EWS services. Double-hop is an issue with NTLM, as your NTLM ticket is only valid for the first hop. Kerberos fixes that, but you still need to impersonate.

ASP.NET - remote screenshot

I made a very very simple small app to take screenshot of the desktop and send to network share. About 10 PC's would have this app installed.
My idea is, that there will be one dashboard in ASP.NET, which simply shows those screenshots on the webpage. So far, easy stuff.
But, because I don't want to clog the network and send the screenshot every 1 minute, I would like to launch the .exe on the remote PC's by demand of ASP.NET user.
Unfortunately I haven't found any information (and I'm a complete ASP.NET n00b), how to launch remote executable IN the context of the remote PC (so I won't see screenshots of ASP server :) )
If there is no such possibility, please advise about other way to solve this.
Update after clarification:
Take a look at the situation from another angle:
Why don't you run a web server on the clients that host an asp.net page that triggers the capture. Then you can, from your root server, simply sent http requests to the clients and fetch the image.
You can try http://CassiniDev.codeplex.com - it supports external IP and hostnames.
And you may also consider simply embedding the CassiniDev-lib (a very simple example is shown here - Using CassiniDev to host ASP.Net in your application, that way you can use the web server as the reciever and the forms app can do whatever it wants on the client.
I am confident in this approach as I designed cassinidev with this as one of the primary use cases.
From asp.net you cannot. It is only HTML/JavaScript once it gets to the browser.
ActiveX is a possibility but it is quite painful and dated and limited. And painful.
The new way to do something like this is to deploy a .net Forms application or WPF app via Click Once.
You can also write a WPF Browser Application but getting the kind of permissions you would need would entail setting the site as full trust.
If a web page could launch an arbitrary .exe file on your machine, that would be a security disaster.
However, since these are your PCs, you can require them to install an ActiveX control of some kind that you could then embed in your ASP.NET page.
As others have said, there is really no way for ASP.Net to call out to the apps, but reversing the control flow should work OK...
I suppose you could have the grabber application running all the time on the users desktop, but have it make a call to a web service / file served by the server that contains an instruction for that instance of the app to grab a screenshot.
Something like...
App : Do I have to do anything? (GET /workinstruction.aspx)
Server : no. (server decides whether to request work, and return the result in (workinstruction.aspx)
App : (waits 1 minute)
App : Do I have to do anything?
Server : yes.
App : (takes screenshot and submits)
App : (waits 1 minute)
App : Do I have to do anything?
etc...
Thank you all for answering, those were interesting approaches to the subject.
Yet due to many factors I ended up with following solution:
Pseudo-service (Windows Forms with tray icon and hidden form) application on client PC's. It is serving as TCP server.
ASP.Net web app on the server, with TCP client function.
On request of the web user, web app is sending preformatted TCP 'activation' string to the chosen PC. Tray app is making a screenshot and sending it to predefined SMB share, available for web app to display.
Thanks again!
I've done this exact thing a few times for monitoring remote display systems. What I found was that using MiniCap.exe to capture image also took video (which was required on remote display systems).
I also used Cassini as described by Sky Sanders with an ASPX-page with the following code.
Then I just reference the page from an img src="http://computer/page.aspx?paramters". (Let me know if you need more info)
<%# Import NameSpace="System.IO" %>
<%# Import NameSpace="System.Drawing" %>
<%# Import NameSpace="System.Drawing.Imaging" %>
<%# Import NameSpace="System.Diagnostics" %>
<%
Response.Buffer = True
Response.BufferOutput = True
Dim CompressionLevel As Integer = 1
Dim compress As Integer = 1
If Not Request.Item("compress") Is Nothing Then
If IsNumeric(Request.Item("compress")) = True Then
CompressionLevel = CInt(Request.Item("compress"))
End If
End If
compress = CompressionLevel
' Resize requested?
Dim SizeX As Integer = 100
Dim SizeY As Integer = 75
If Not Request.Item("width") Is Nothing Then
If IsNumeric(Request.Item("width")) = True Then
SizeX = CInt(Request.Item("width"))
CompressionLevel = 10
End If
End If
If Not Request.Item("height") Is Nothing Then
If IsNumeric(Request.Item("height")) = True Then
SizeY = CInt(Request.Item("height"))
CompressionLevel = 10
End If
End If
Dim Region As String = ""
If Not Request.Item("region") Is Nothing Then
Region = Request.Item("region")
End If
Dim XS As Integer = 0
Dim YS As Integer = 0
Dim XE As Integer = 1023
Dim YE As Integer = 766
Try
If Region.IndexOf(",") > -1 Then
Dim Rec() As String = Region.Split(",")
If Rec.GetUpperBound(0) >= 3 Then
If IsNumeric(Rec(0)) Then XS = Rec(0)
If IsNumeric(Rec(1)) Then YS = Rec(1)
If IsNumeric(Rec(2)) Then XE = Rec(2)
If IsNumeric(Rec(3)) Then YE = Rec(3)
End If
End If
Catch : End Try
Dim FileType As String = "jpg"
Dim MimeType As String = "jpeg"
If Not Request.Item("filetype") Is Nothing Then
FileType = Request.Item("filetype")
MimeType = FileType
End If
If Not Request.Item("mimetype") Is Nothing Then
FileType = Request.Item("mimetype")
End If
Dim ImageFile As String = ""
Dim ImageThumbFile As String = ""
Dim ImageFolder As String = Server.MapPath("~/ScreenShots/")
If IO.Directory.Exists(ImageFolder) = False Then
IO.Directory.CreateDirectory(ImageFolder)
End If
' Delete files older than 30 minutes
For Each File As String In IO.Directory.GetFiles(ImageFolder)
Response.Write("File: " & File & "<br>")
If IO.File.GetCreationTimeUtc(File).AddMinutes(30) < Now.ToUniversalTime Then
IO.File.Delete(File)
End If
Next
' Find available filename
Dim tmpC As Integer = 0
While tmpC < 100
tmpC += 1
ImageFile = "ScreenShot_" & CStr(tmpC).PadLeft(5, "0") & "." & FileType
ImageThumbFile = "ScreenShot_" & CStr(tmpC).PadLeft(5, "0") & "_thumb." & FileType
If IO.File.Exists(ImageFolder & "\" & ImageFile) = False Then
' Found our filename
' Reserve it
Dim ios As IO.FileStream = IO.File.Create(ImageFolder & "\" & ImageFile)
ios.Close()
ios = Nothing
Exit While
End If
End While
' Run MiniCap
' " -capturedesktop" & _
Dim CMD As String = """" & Server.MapPath("/MiniCap.EXE") & """" & _
" -save """ & ImageFolder & "\" & ImageFile & """" & _
" -captureregion " & XS & " " & YS & " " & XE & " " & YE & _
" -exit" & _
" -compress " & CompressionLevel
If Not CMD Is Nothing Then
Dim myProcess As Process = New Process
Dim RouteFB As String
With myProcess
With .StartInfo
.FileName = "cmd.exe"
.UseShellExecute = False
.CreateNoWindow = True
.RedirectStandardInput = True
.RedirectStandardOutput = True
.RedirectStandardError = True
End With
.Start()
End With
Dim sIn As IO.StreamWriter = myProcess.StandardInput
sIn.AutoFlush = True
' Create stream reader/writer references
Dim sOut As IO.StreamReader = myProcess.StandardOutput
Dim sErr As IO.StreamReader = myProcess.StandardError
' Send commands
sIn.Write(CMD & System.Environment.NewLine)
sIn.Write("exit" & System.Environment.NewLine)
' Wait one second
'Threading.Thread.CurrentThread.Sleep(60000)
' Read all data
Response.Write(sOut.ReadToEnd)
' Kill process if still running
If Not myProcess.HasExited Then
myProcess.Kill()
End If
sIn.Close()
sOut.Close()
sErr.Close()
myProcess.Close()
End If
Response.Clear()
Response.ClearContent()
If Not Request.Item("width") Is Nothing Or Not Request.Item("length") Is Nothing Then
' Resize, making thumbnail in desired size
Dim b As Bitmap = Bitmap.FromFile(ImageFolder & "\" & ImageFile)
Dim thumb As Bitmap = b.GetThumbnailImage(SizeX, SizeY, Nothing, IntPtr.Zero)
' Jpeg image codec
Dim jpegCodec As ImageCodecInfo
' Get image codecs for all image formats
Dim codecs As ImageCodecInfo() = ImageCodecInfo.GetImageEncoders()
' Find the correct image codec
For i As Integer = 0 To codecs.Length - 1
If (codecs(i).MimeType = "image/" & MimeType) Then
jpegCodec = codecs(i)
Exit For
End If
Next i
Dim qualityParam As New EncoderParameter(System.Drawing.Imaging.Encoder.Quality, compress * 10)
Dim encoderParams As New EncoderParameters(1)
encoderParams.Param(0) = qualityParam
thumb.Save(ImageFolder & "\" & ImageThumbFile, jpegCodec, encoderParams)
thumb.Dispose()
b.Dispose()
' Send thumb
Response.TransmitFile(ImageFolder & "\" & ImageThumbFile)
Else
' Send normal file
Response.TransmitFile(ImageFolder & "\" & ImageFile)
End If
Response.End()
%>

Resources