ASP.NET - remote screenshot - asp.net

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()
%>

Related

VB.NET FTP Picture Upload Error [duplicate]

This question already has answers here:
Zip file is getting corrupted after downloading from server in C#
(3 answers)
Closed 4 years ago.
I am trying to allow authenticated users to upload pictures to the server through FTP. The code works for the most part. The part that doesn't is that there is an issue in uploading the file. I have tried to upload a few different pictures and all of them are larger on the server and therefore, not properly constructed.
One picture I tried is 4.56MB on my computer and 8.24MB on the server. When I load the picture in Photo, it states "We can't open this file." The page location is at http://troop7bhac.com/pages/slideshowedit.aspx. The following is the VB.NET code behind the upload:
Sub uploadFile_Click(sender As Object, e As EventArgs)
lblUploadErrors.InnerHtml = ""
If (lstSlideshowChoose.SelectedValue = "") Then
lblUploadErrors.InnerHtml = "<p>A slideshow must be selected.</p>"
Else
If (FileUpload1.HasFile) Then
Dim nameList() As String
Dim successList() As String
Dim i As Integer = 0
For Each file As HttpPostedFile In FileUpload1.PostedFiles
Dim fileBytes() As Byte = Nothing
Dim fileName As String = Path.GetFileName(file.FileName)
Dim photoRE As New Regex("^[A-z0-9 _]{1,}\.jpg|JPG|jpeg|JPEG|png|PNG+$")
Dim photoSuccess As Boolean = photoRE.Match(fileName).Success
ReDim Preserve nameList(i)
ReDim Preserve successList(i)
If (photoSuccess = True) Then
Using fileStream As New StreamReader(file.InputStream)
fileBytes = Encoding.UTF8.GetBytes(fileStream.ReadToEnd())
fileStream.Close()
End Using
Try
Dim request As FtpWebRequest = DirectCast(WebRequest.Create(ftpPath & lstSlideshowChoose.SelectedValue & "/" & fileName), FtpWebRequest)
request.Method = WebRequestMethods.Ftp.UploadFile
request.Credentials = New NetworkCredential(ftpUser, ftpPass)
Using uploadStream As Stream = request.GetRequestStream()
uploadStream.Write(fileBytes, 0, fileBytes.Length)
uploadStream.Close()
End Using
Dim response As FtpWebResponse = DirectCast(request.GetResponse(), FtpWebResponse)
response.Close()
successList(i) = "Success "
Catch ex As Exception
successList(i) = "Failed "
End Try
Else
successList(i) = "Failed "
End If
nameList(i) = fileName
i += 1
Next
For x As Integer = 0 To nameList.Count - 1
lblUploadErrors.InnerHtml += "<p>" & successList(x) & nameList(x) & "</p>"
Next
Else
lblUploadErrors.InnerHtml = "<p>You have not selected a picture to upload.</p>"
End If
End If
End Sub
The files are obtained through an ASP.NET FileUpload control. The control has been set to allow multiple files at once.
Any help to figure out why the pictures are not uploading properly would be greatly appreciated.
EDIT: I tried Martin Prikryl's possible duplicate solution. Had to change it from C# to VB.NET. It failed. I tried David Sdot's solution and it also failed. Both solutions returned the same errors.
If the page was ran on my local machine, it returned "C:\Program Files (x86)\IIS Express\PictureName.JPG." If the page was ran on the server, it returned "C:\Windows\SysWOW64\inetsrv\PictureName.JPG." Both errors are of the System.IO.FileNotFoundException class.
Your Problem is here:
Using fileStream As New StreamReader(file.InputStream)
fileBytes = Encoding.UTF8.GetBytes(fileStream.ReadToEnd())
fileStream.Close()
Using
Your image is read as text. From this text you get the bytes UTF8 byte values, thats why your image is nearly twice the size when uplaoded. You need the bytes from the image, without converting them to something else.
fileBytes = File.ReadAllBytes(file.FileName)

Is it possible to copy files from a UNC source to a webDav destination with a script?

I work in a very large, complex Intranet environment. I have run into a very unique issue that I cannot seem to resolve.
Forwarning
The technologies I mention are very outdated and that is the way is has to stay. I work in a very large enterprise and they have a ton of legacy things in place. I normally work on the modern side of things, but this got placed in my lap.
The problem:
We have a file located on our IIS 7.x server with path \serverName\shareName\wwwroot\myfile.jpg. I need to copy this file to a webDav location of a DIFFERENT web server using ASP , vbscript, or another similar web technology. For a multitude of security implications, I don't have access to the webDav UNC path, only the http: path. I am able to map this drive and access the http: location using windows explorer. I can even manually copy files, create files, and delete them. However, when I try to use a script, I get no where.
I am not great with vbscript so bare with my attempts:
Attempt 1:
Set oShell = CreateObject("WScript.Shell")
strCommand = oShell.Run("Xcopy ""sourceLocation"" ""destination location"" /S /Y", 0, True)
If strCommand <> 0 Then
MsgBox "File Copy Error: " & strCommand
Else
MsgBox "Done"
End If
Attempt 2:
<%
dim objFSOpublish
set objFSOpublish = CreateObject("Scripting.FileSystemObject")
strCurrentUNCfull = "sourcePath"
mPublishPath = "destinationPath"
objFSOpublish.CopyFile strCurrentUNCfull, mPublishPath
set objFSOpublish = nothing
%>
I have no idea if this is even possible to do without the webDav UNC path because I don't have much experience with webDav. If it is possible I have exhausted my limited knowledge in this space and need help badly. I scoured Google tirelessly trying to find a similar issue to no avail. Any and all help or direction will be greatly appreciated.
You're going to want to do something like this:
On Error Resume Next
sUrl = "YourURLHere"
sFile = "UNCPathToYourFile"
'Here we are just reading your file into an ODB
'stream so we can manipulate it
Set oStream = CreateObject("ADODB.Stream")
oStream.Mode = 3
oStream.Type = 1
oStream.Open
oStream.LoadFromFile(sFile)
'Here we are doing the upload of the oStream
'object we just created.
Set oHTTP = CreateObject("MSXML2.ServerXMLHTTP")
oHTTP.Open "POST", sUrl, False
oHTTP.SetRequestHeader "Content-Length", oStream.Size
oHTTP.Send oStream.Read(oStream.Size)
'Check for errors.
If Err = 0 Then
Wscript.Echo oHTTP.responseText
Else
Wscript.Echo "Upload Error!" & vbCrLf & Err.Description
End If
'Optionally close out our objects
oStream.Close
Set oStream = Nothing
Set oHTTP = Nothing
Here is the code I am currently using with the actual file path redacted. Let me know if you see anything that is incorrect.
The page is saved as a .ASP.
<%
sUrl = "http://server.site.com:80/subDomain/wwwroot/"
sFile = "\\server\developmentShare\wwwroot\page.htm"
'Here we are just reading your file into an ODB
'stream so we can manipulate it
Set oStream = Server.CreateObject("ADODB.Stream")
oStream.Mode = 3
oStream.Type = 1
oStream.Open
oStream.LoadFromFile(sFile)
'Here we are doing the upload of the oStream
'object we just created.
Set oHTTP = CreateObject("MSXML2.ServerXMLHTTP")
oHTTP.Open "POST", sUrl, False
oHTTP.SetRequestHeader "Content-Length", oStream.Size
oHTTP.Send oStream.Read(oStream.Size)
'Check for errors.
If Err = 0 Then
Wscript.Echo oHTTP.responseText
Else
Wscript.Echo "Upload Error!" & vbCrLf & Err.Description
End If
'Optionally close out our objects
oStream.Close
Set oStream = Nothing
Set oHTTP = Nothing
%>

Set IP address from a list in VBS

Ok so i'm in the process of imaging a bunch of PC's with Fog. My boss is a stickler for setting everything manually, he won't even let me use Print servers to manage the printers...
Anyway, to make a long story short I've made great strides by writing a bunch of printer install scripts and a couple other small monitoring and other scripts.
So it's now come down to setting IP addresses, which as usual must be set static without the normal AD\DHCP ezmode.
So i was hoping to get some help with this new script i Frankensteined together.
This script "Should"
Read the hostname it's run on (Working!)
Open Computerlist.csv on a network share (Mostly working)
Parse ComputerList.csv, looking for hostname (Works usually, but is case sensative)
take the information listed for hostname, and set variables (Looses .'s when pulled)
Use those variables to configure the network connection. (problematic because of the above #4)
I'm actually pretty surprised i wasn't able to google search a script that had already been built to do this.
Here is what i've cobbled together so far, it seems to be pretty close but I'm missing something wrong and i just can't sort it out.
option explicit
Dim WshShell
Dim ObjShell
Dim objSysInfo
Dim strComputerName
Dim strFile
Set WshShell = WScript.CreateObject("WScript.Shell")
If WScript.Arguments.length = 0 Then
Set ObjShell = CreateObject("Shell.Application")
ObjShell.ShellExecute "wscript.exe", """" & _
WScript.ScriptFullName & """" &_
" RunAsAdministrator", , "runas", 1
Else
end if
'* Pulls Computer name and sets it to variable
Set objSysInfo = CreateObject( "WinNTSystemInfo" )
strComputerName = objSysInfo.ComputerName
'* Loop through CSV file, read entries, store them in an array
dim CONNECTION : set CONNECTION = CreateObject("ADODB.CONNECTION")
dim RECORDSET : set RECORDSET = CreateObject("ADODB.RECORDSET")
CONNECTION.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\carmichaels\e\PCSetup\IPchanger\;Extended Properties=""text;HDR=YES;FMT=Delimited"""
RECORDSET.Open "SELECT * FROM ComputerList.csv WHERE ComputerName = '" & strComputerName & "'", CONNECTION, 3, 3
' //// For testing \\\\
WScript.Echo RECORDSET.Source
' \\\\ For testing ////
if RECORDSET.EOF then
WScript.Echo "Record not found"
WScript.Quit
else
dim strIPAddress : strIPAddress = RECORDSET("IPAddress") & ""
dim strSubnetMask : strSubnetMask = RECORDSET("SubnetMask") & ""
dim strGateway : strGateway = RECORDSET("Gateway") & ""
dim intGatewayMetric : intGatewayMetric = 1
dim strDns1 : strDns1 = RECORDSET("Dns1") & ""
dim strDns2 : strDns2 = RECORDSET("Dns2") & ""
dim strDns3 : strDns3 = RECORDSET("Dns3") & ""
WScript.Echo strIPAddress
end if
'* Set IP address information stored in variables
Set objShell = WScript.CreateObject("Wscript.Shell")
objShell.Run "netsh interface ip set address name=""Local Area Connection"" static " & strIPAddress & " " & strSubnetMask & " " & strGateway & " " & intGatewayMetric, 0, True
objShell.Run "netsh interface ip set dns name=""Local Area Connection"" static "& strDns1, 0, True
objShell.Run "netsh interface ip add dns name=""Local Area Connection"" addr="& strDns2, 0, True
objShell.Run "netsh interface ip add dns name=""Local Area Connection"" addr="& strDns3, 0, True
Set objShell = Nothing
My problem is when i run this script, It claims line 28 chr 1 cannot open the file (on 32 bit machines).
And on a 64 Bit machine, (i run it with the following in a .bat [%windir%\SysWoW64\cscript \server\share\folder\folder\IPchanger.vbs] ) it runs through but the IP address is missing dots. ex. 10.1.0.57 appears as 10.1057 in my test window, and will fail to run again claiming the file is open or locked.
Here's the CSV file
ComputerName,IPAddress,SubnetMask,Gateway,Dns1,Dns2,Dns3
CLONE2,10.1.0.57,255.255.255.0,10.1.0.1,10.1.0.18,10.1.0.13,10.1.0.12
Dont know about your file open errors, for me line 28 is
Set objShell = WScript.CreateObject("Wscript.Shell")
But to avoid the problem with the dots, using Jet OLEDB text filter, you need to define a Schema.ini file for the csv. See http://msdn.microsoft.com/en-us/library/windows/desktop/ms709353%28v=vs.85%29.aspx
I think Jet asumes your IPs to be decimal numbers, not text.

How to generate and send to client Excel report in ASP.NET

I am new to the whole issue of generating/sending Excel report in ASP.net.
The Code below sometimes does not work for large amount of data (large Excel report), but only if user, located not in our company, requests it from his browser. It always works if I run it, and I am located in the same building where server is.
Client has IE9 and MS Office 2010. Client does not get any errors. Client simply does not get report after long wait time. Seems to timeout without errors.
Are there any alternative to the approach below, for providing client with large Excel report ?
Anything done wrong in the code below that may cause the problem?
What is the best=robust way to generate report for the client that can be opened on the client side in Excel ?
Response.ContentType = "application/ms-excel"
Response.AddHeader("Content-Disposition", "attachment; filename=" + ReportName + ".xls")
Response.Write("<table border =1>")
For Each ch As ColumnHeaders In arrCh
If ch.ColumnName <> "" Then
pCh = pCh & "<td><b>" & ch.ColumnName & "</b></td>"
pColCount = pColCount + 1
End If
Next
If pExtraHeader <> "" Then
Response.Write(pExtraHeader)
End If
Response.Write("<tr>" & pCh & "</tr>")
If oSQLDataReader.HasRows Then
Do While oSQLDataReader.Read()
Response.Write("<tr>")
For I = 0 To arrCh.Count - 1
If arrCh(I + 1).columnname <> "" Then
Response.Write("<td>" & strColumnValue & "</td>")
If arrCh.Item(I + 1).isTotal = True Then
arrCh.Item(I + 1).placeholder = CDbl(arrCh.Item(I + 1).placeholder) + CDbl(oSQLDataReader.GetValue(I))
End If
End If
Next
Response.Write("</tr>")
Loop
Dim pTotal As String = ""
For Each ch As ColumnHeaders In arrCh
If ch.ColumnName <> "" Then
pTotal = pTotal & "<td><b>" & strColumnValue & "</b></td>"
End If
Next
Response.Write("<tr>" & pTotal & "</tr>"
End If
Response.Write("</table>")
Is that all the code? Are you flushing the response and finalizing it?
Other than that, in the case of excel there are lots of server components to automatically generate an excel workbook and return the file as an attachment to the client (all processing is done on the server).
And lastly (and this is always a last resort measure) you have Excel Automation on the server.
Check this answer, here's a breakdown of the different alternatives you have available.

paypal nvp .net sdk error

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.

Resources