Can someone help me with an ASP.NET page

  • Thread starter Thread starter Brent White
  • Start date Start date
B

Brent White

I am probably too dense to figure it out for myself, so I am asking
here. I am writing an ASP.NET page in VB.NET 2005 that will allow a
user to scan (using a Windows CE based scanner with IE trying to
impersonate a Windows XP session) items to an order, then print to a
network printer. I had some great help from vbCity in how to print
the document. From a PC running Windows XP, it works great. From the
scanner, which does not have a LAN login, it works until the page
tries to output the text string to the printer.

This is the page's VB code:

Imports System.Data.SqlClient
Imports System.Data
Imports System.String
Imports System.Drawing.Printing
Imports System.Drawing
Partial Public Class WebForm1
Inherits System.Web.UI.Page
Dim quantity As Long
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Me.TextBox1.Focus()
End Sub
Private WithEvents myprinter As New PrintDocument()
Private Sub myPrinter_PrintPage(ByVal sender As Object, ByVal e As
PrintPageEventArgs) Handles myprinter.PrintPage

Dim leftMargin As Single = e.MarginBounds.Left
Dim topMargin As Single = e.MarginBounds.Top
Dim printFont = New Font("Courier New", 10)
Dim sb As StringBuilder = New StringBuilder()
Dim SQLCN As New SqlConnection
("server=JOMAR;uid=reports;pwd=reports;database=ee8idbbd")
Dim SQLCOMM As New SqlCommand
Dim sqlrs As SqlDataReader
SQLCN.Open()
SQLCOMM.Connection = SQLCN
SQLCOMM.CommandType = CommandType.StoredProcedure
SQLCOMM.CommandText = "bdg_procSalesOrder"
SQLCOMM.Parameters.AddWithValue("@ORDERNUMBER", Session
("OrderNumber"))
sqlrs = SQLCOMM.ExecuteReader

sb.Append("ORDER #:" + Session("OrderNumber") + " " +
"DateTime: " + DateTime.Now.ToString() + Environment.NewLine +
Environment.NewLine)
sb.Append(" " + "STYLE " + "QUANTITY " +
"PRICE " + "TOTAL " + Environment.NewLine +
Environment.NewLine)
While sqlrs.Read
sb.Append("LINE " + sqlrs(1).ToString.PadRight(5 - Len
(sqlrs(1).ToString)) + sqlrs(2).ToString.PadRight(14 - Len(sqlrs
(2).ToString)) + sqlrs(3).ToString.PadRight(14 - Len(sqlrs
(3).ToString)) + Format(sqlrs(4).ToString, "Currency").PadRight(14 -
Len(Format(sqlrs(4).ToString, "Currency"))) + Format(sqlrs
(5).ToString, "Currency").PadRight(14 - Len(Format(sqlrs(5).ToString,
"Currency"))) + Environment.NewLine + Environment.NewLine)
End While
e.Graphics.DrawString(sb.ToString(), printFont, Brushes.Black,
leftMargin, topMargin)

End Sub



Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim sqlcn As New SqlConnection
("server=JOMAR;uid=reports;pwd=reports;database=ee8idbbd")
Dim sqlcomm As New SqlCommand
Dim sqlprice As New SqlCommand
Dim ERROUT As Long
sqlcn.Open()
If Left(Me.TextBox1.Text, 1) = "S" Then
'Response.Write("NEW STYLE")
'Dim stringresult As String
Try
sqlcomm.Connection = sqlcn
sqlcomm.CommandText = "bdg_fillgsorder"
sqlcomm.CommandType = CommandType.StoredProcedure
sqlcomm.Parameters.AddWithValue("@STYLE", Session
("STYLE"))
sqlcomm.Parameters.AddWithValue("@ORDER_NUMBER",
Session("OrderNumber"))
sqlcomm.Parameters.AddWithValue("@ORDER_LINE", Session
("LineNumber"))
sqlcomm.Parameters.AddWithValue("@QUANTITY", Session
("quantity"))
sqlcomm.Parameters.AddWithValue("@UnitPrice", Session
("PRICE"))
'sqlcomm.Parameters(0).SqlDbType = SqlDbType.VarChar
'sqlcomm.Parameters(0).Size = 15
'sqlcomm.Parameters(0).Direction =
ParameterDirection.Output
sqlcomm.ExecuteNonQuery()
Session("STYLE") = Right(Me.TextBox1.Text, Len
(Me.TextBox1.Text) - 1)
sqlprice.Connection = sqlcn
sqlprice.CommandText = "bdg_GSPricing"
sqlprice.CommandType = CommandType.StoredProcedure
sqlprice.Parameters.AddWithValue("@STYLE", Session
("STYLE"))
'sqlcomm.Parameters(0).SqlDbType = SqlDbType.VarChar
'sqlcomm.Parameters(0).Size = 15
'sqlcomm.Parameters(0).Direction =
ParameterDirection.Output
Dim oNum As Double
oNum = (sqlprice.ExecuteScalar())
' stringresult = oNum.ToString
Session("PRICE") = oNum
'Session("LineNumber") = Session("LineNumber") + 1
Session("quantity") = 0
Me.TextBox1.Text = ""
Me.TextBox1.Focus()
Catch EX As Exception
Response.Write("Invalid Style")
errout = 1
'Beep()
Finally ' Session("STYLE") = null
If ERROUT = 0 Then
Session("LineNumber") = Session("LineNumber") + 1
Session("quantity") = 0
Me.TextBox1.Text = ""
Me.TextBox1.Focus()
Else
Me.TextBox1.Text = ""
Me.TextBox1.Focus()
End If
'Server.Transfer("Style.aspx")
End Try
ElseIf Me.TextBox1.Text = "END" Then
Response.Write("Finished")
sqlcomm.Connection = sqlcn
sqlcomm.CommandText = "bdg_fillgsorder"
sqlcomm.CommandType = CommandType.StoredProcedure
sqlcomm.Parameters.AddWithValue("@STYLE", Session
("STYLE"))
sqlcomm.Parameters.AddWithValue("@ORDER_NUMBER", Session
("OrderNumber"))
sqlcomm.Parameters.AddWithValue("@ORDER_LINE", Session
("LineNumber"))
sqlcomm.Parameters.AddWithValue("@QUANTITY", Session
("quantity"))
sqlcomm.Parameters.AddWithValue("@UnitPrice", Session
("PRICE"))
'sqlcomm.Parameters(0).SqlDbType = SqlDbType.VarChar
'sqlcomm.Parameters(0).Size = 15
'sqlcomm.Parameters(0).Direction =
ParameterDirection.Output
sqlcomm.ExecuteNonQuery()
sqlcn.Close()
myprinter.PrinterSettings.PrinterName = "\
\195.1.2.222\hp3"
myprinter.Print()
Server.Transfer("Default.aspx", True)
ElseIf Not IsNumeric(Me.TextBox1.Text) Then
Response.Write("Invalid Number")
Me.TextBox1.Text = ""
Me.TextBox1.Focus()
Else
Session("quantity") = Session("quantity") + CLng
(Me.TextBox1.Text)
Response.Write(Session("Quantity").ToString + " UNITS OF
STYLE " + Session("STYLE").ToString)
Me.TextBox1.Text = ""
Me.TextBox1.Focus()
End If
End Sub
End Class


When I run this code on the PC, I get a print out (not the prettiest
printout but that's something different) on the printer \
\195.1.2.222\hp3

Do the same thing on the scanner, you scan the barcode "END" and it
gets the error:

InvalidPrinterException

The error message on the screen says that the settings to access
printer '\\195.1.2.222\hp3' are not valid (I turned off the custom
error page...it's an intranet webpage, anyway).

I see some instructions on how to do this, but they are very vague.
The IIS runs on a Windows 2000 Advanced Server box. If I could put a
new instance of IIS and register it on a 2003 box this quickly, I
would, but I fear it will interfere with other applications running on
the box.

Can someone please enlighten me with specifics on how to do this? I
would greatly appreciate it.
 
I am probably too dense to figure it out for myself, so I am asking
here.  I am writing an ASP.NET page in VB.NET 2005 that will allow a
user to scan (using a Windows CE based scanner with IE trying to
impersonate a Windows XP session) items to an order, then print to a
network printer.  I had some great help from vbCity in how to print
the document.  From a PC running Windows XP, it works great.  From the
scanner, which does not have a LAN login, it works until the page
tries to output the text string to the printer.

Check current identity from XP and CE to see what you get. I suppose
you run application under different identity on CE.

<%= User.Identity.Name %>
 
Check current identity from XP and CE to see what you get. I suppose
you run application under different identity on CE.

<%= User.Identity.Name %>

I'm not sure how to do that. Do I need to include a login name and
password?
 
I'm not sure how to do that.  Do I need to include a login name and
password?

Put it somewhere in aspx page. This is just a test output of the name
of current user. Even better if you check WindowsIdentity. Make a new
aspx file add

<%@Page%>
Hello, <%=System.Security.Principal.WindowsIdentity.GetCurrent().Name
%>

put it to your server and open from XP box and then from CE.
 
Put it somewhere in aspx page. This is just a test output of the name
of current user. Even better if you check WindowsIdentity. Make a new
aspx file add

<%@Page%>
Hello, <%=System.Security.Principal.WindowsIdentity.GetCurrent().Name
%>

put it to your server and open from XP box and then from CE.- Hide quotedtext -

- Show quoted text -

I guess really I should clarify. How do I fix this? Do I have to
impersonate a Windows user with the webpage? That's the how I'm
asking for.
 
Put it somewhere in aspx page. This is just a test output of the name
of current user. Even better if you check WindowsIdentity. Make a new
aspx file add

<%@Page%>
Hello, <%=System.Security.Principal.WindowsIdentity.GetCurrent().Name
%>

put it to your server and open from XP box and then from CE.- Hide quotedtext -

- Show quoted text -

I did that, and the CE program welcomes me as OLDJOMAR\ASPNET

I get BADGER\bwhite from my XP box

How do I change it so it always authenticates as a network user (one
without admin rights, of course)
 
I did that, and the CE program welcomes me as OLDJOMAR\ASPNET

I get BADGER\bwhite from my XP box

How do I change it so it always authenticates as a network user (one
without admin rights, of course)- Hide quoted text -

- Show quoted text -

Hi Brent,

this shows me that from CE you run the site under local server account
(OLDJOMAR\ASPNET) which probably has no access to the printer.

You might want to take a look at

http://support.microsoft.com/kb/306158
http://msdn.microsoft.com/en-us/library/aa302377.aspx

I don't know how you login on CE. If there is no personal account, you
can try to impersonate the IIS Authenticated Account or User (see link
#1)

The second link contains descriptions of the principal and identity
objects used by ASP.NET, as well as their expected values under
various combinations of IIS and ASP.NET authentication schemes.
 
Hi Brent,

this shows me that from CE you run the site under local server account
(OLDJOMAR\ASPNET) which probably has no access to the printer.

You might want to take a look at

http://support.microsoft.com/kb/306158http://msdn.microsoft.com/en-us/library/aa302377.aspx

I don't know how you login on CE. If there is no personal account, you
can try to impersonate the IIS Authenticated Account or User (see link
#1)

The second link contains descriptions of the principal and identity
objects used by ASP.NET, as well as their expected values under
various combinations of IIS and ASP.NET authentication schemes.- Hide quoted text -

- Show quoted text -

I got it working.

I set up the Impersonation for the ASP.NET web directory /garments to
a network user and it now prints even from the scanner.

Thank you for your help.
 
I got it working.

I set up the Impersonation for the ASP.NET web directory /garments to
a network user and it now prints even from the scanner.

Thank you for your help.- Hide quoted text -

- Show quoted text -

Glad, you got it working. Note, for security reasons, the identity
section supports storage of encrypted userName and password attributes
in the registry. Read more at http://msdn.microsoft.com/en-us/library/72wdk8cc.aspx
 
Back
Top