Go to: http :// med.navy.mil/sites/nmlc/Pages/default.aspx and click on Home (MIL/GOVT)
Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab:...
-
date post
21-Dec-2015 -
Category
Documents
-
view
216 -
download
1
Transcript of Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab:...
![Page 1: Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab: Zip drive dchao Default home page –Default.aspx,](https://reader036.fdocuments.us/reader036/viewer/2022081516/56649d6b5503460f94a4a4a3/html5/thumbnails/1.jpg)
Introduction to VB.Net Internet Tools
![Page 2: Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab: Zip drive dchao Default home page –Default.aspx,](https://reader036.fdocuments.us/reader036/viewer/2022081516/56649d6b5503460f94a4a4a3/html5/thumbnails/2.jpg)
Web Server
• Default directory– C:\InetPub\wwwroot– Computer lab: Zip drive
• dchao
• Default home page– Default.aspx, default.asp, default.htm
![Page 3: Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab: Zip drive dchao Default home page –Default.aspx,](https://reader036.fdocuments.us/reader036/viewer/2022081516/56649d6b5503460f94a4a4a3/html5/thumbnails/3.jpg)
Web Project
• File/New/ ASP.Net Application
• Website folder
• Web form:– Webform.aspx
• Design view and HTML view
– WebForm.Aspx.VB• CodeBehind
![Page 4: Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab: Zip drive dchao Default home page –Default.aspx,](https://reader036.fdocuments.us/reader036/viewer/2022081516/56649d6b5503460f94a4a4a3/html5/thumbnails/4.jpg)
Web Data Form
• Web Data Form Wizard:– Project/Add Web Form/Data Form Wizard
![Page 5: Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab: Zip drive dchao Default home page –Default.aspx,](https://reader036.fdocuments.us/reader036/viewer/2022081516/56649d6b5503460f94a4a4a3/html5/thumbnails/5.jpg)
Bind the DataReader to a DataGrid
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\salesDB.mdb" Dim objConn As New OleDbConnection(strConn) Dim strSQL As String = "select * from customer;" Dim objComm As New OleDbCommand(strSQL, objConn) Dim Results As String objConn.Open() Dim objDataReader As OleDbDataReader objDataReader = objComm.ExecuteReader() DataGrid1.DataSource = objDataReader DataGrid1.DataBind()
Note: DataGrid1.DataBind()
![Page 6: Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab: Zip drive dchao Default home page –Default.aspx,](https://reader036.fdocuments.us/reader036/viewer/2022081516/56649d6b5503460f94a4a4a3/html5/thumbnails/6.jpg)
ASP.NET
• ASP.NET is a server-side technology for creating dynamic web pages.
• ASP.NET allows you to use a selection of full programming languages. The default language is VB .NET.
• ASP.NET files have a .aspx extension.
![Page 7: Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab: Zip drive dchao Default home page –Default.aspx,](https://reader036.fdocuments.us/reader036/viewer/2022081516/56649d6b5503460f94a4a4a3/html5/thumbnails/7.jpg)
ASP.NET Object Model
Client Server
Request Object
Response Object
Server Object
SessionObject
Application
Object
![Page 8: Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab: Zip drive dchao Default home page –Default.aspx,](https://reader036.fdocuments.us/reader036/viewer/2022081516/56649d6b5503460f94a4a4a3/html5/thumbnails/8.jpg)
ASP.NET Request Object• When a page is requested, much
information is passed along with the request, such as the URL, queryString, and data from a form. The request object allows you to get the information passed along with the request.
• It is created from the System.Web.HttpRequest class.
![Page 9: Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab: Zip drive dchao Default home page –Default.aspx,](https://reader036.fdocuments.us/reader036/viewer/2022081516/56649d6b5503460f94a4a4a3/html5/thumbnails/9.jpg)
FORM Tag
• Form attribute:– Action: Specify the URL of a program on a server or an
email address to which a form’s data will be submitted.
– Method: • Get: the form’s data is appended to the URL specified by the
Action attribute as a QueryString.
• Post: A prefered method for database processing. Form’s data is sent separately from the URL.
– Name: Form’s name
![Page 10: Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab: Zip drive dchao Default home page –Default.aspx,](https://reader036.fdocuments.us/reader036/viewer/2022081516/56649d6b5503460f94a4a4a3/html5/thumbnails/10.jpg)
QueryString
• A QueryString is a set of name=value pairs appended to a target URL.
• It can be used to pass information from one webpage to another.
• Example: • <A Href=“
http://my.com/Target.htm?CustID=C1&Cname=Chao”>
![Page 11: Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab: Zip drive dchao Default home page –Default.aspx,](https://reader036.fdocuments.us/reader036/viewer/2022081516/56649d6b5503460f94a4a4a3/html5/thumbnails/11.jpg)
Request Object Collections
• QueryString– http://my.com/Target.htm?CustID=C1&CustName=Chao
– cid = Request.queryString(“CustID”)
– cName=Request.queryString(“CustName”)
• Form– A form with two text boxes:CustID, CustName– cid = Request.Form(“CustID”)
– cName=Request.Form(“CustName”)
• Cookies
![Page 12: Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab: Zip drive dchao Default home page –Default.aspx,](https://reader036.fdocuments.us/reader036/viewer/2022081516/56649d6b5503460f94a4a4a3/html5/thumbnails/12.jpg)
ASP.NET Response Object
• This object allows you to send information back to client.
• It is created from the System.Web.HttpResponse class.
• Properties:– Cookies (a collection)
• Methods:– Response.Write – Response.Redirect (“URL”)
• Demo: testReqForm.htm, testReqForm.aspx
![Page 13: Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab: Zip drive dchao Default home page –Default.aspx,](https://reader036.fdocuments.us/reader036/viewer/2022081516/56649d6b5503460f94a4a4a3/html5/thumbnails/13.jpg)
Downloading Internet Resources
• Download the HTML of a web page and display it in a text box.– System.URI
• A class for expressing a Uniform Resource Identifier.
– System.Net.WebRequest• Makes a request to a Uniform Resource Identifier.
– WebResponse• Provides a response from a Uniform Resource
Identifier.
• Demo: MyBrowser/GetWebPage
![Page 14: Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab: Zip drive dchao Default home page –Default.aspx,](https://reader036.fdocuments.us/reader036/viewer/2022081516/56649d6b5503460f94a4a4a3/html5/thumbnails/14.jpg)
Imports System.IO
Imports System.Net
Imports System.TextPrivate Sub BtnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnGo.Click
Dim URI As New Uri(txtURL.Text)
Dim request As WebRequest = WebRequest.Create(URI)
Dim response As WebResponse = request.GetResponse
Dim stream As Stream = response.GetResponseStream
Dim readStream As New StreamReader(stream)
Dim webData As String = readStream.ReadToEnd
stream.Close()
readStream.Close()
txtData.Text = webData
End sub
![Page 15: Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab: Zip drive dchao Default home page –Default.aspx,](https://reader036.fdocuments.us/reader036/viewer/2022081516/56649d6b5503460f94a4a4a3/html5/thumbnails/15.jpg)
Change Downloaded Page
• For example, use string’s Replace method to change page content.– webData = webData.Replace("Chao", "You")
• Search/Replace with Regular Expression
![Page 16: Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab: Zip drive dchao Default home page –Default.aspx,](https://reader036.fdocuments.us/reader036/viewer/2022081516/56649d6b5503460f94a4a4a3/html5/thumbnails/16.jpg)
Using the WebClient Class
• This class wraps the Request and Response classes.
• Methods:– DownloadData: Returns a byte array from an
Internet address.– DownloadFile: Save a downloaded file.– OpenRead: Returns a stream from an Internet
address.
![Page 17: Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab: Zip drive dchao Default home page –Default.aspx,](https://reader036.fdocuments.us/reader036/viewer/2022081516/56649d6b5503460f94a4a4a3/html5/thumbnails/17.jpg)
UTFEncoding Class
• This class encodes Unicode characters using UCS Transformation Format, 8-bit form (UTF-8). This encoding supports all Unicode character
• Method: GetString– Decodes the specified byte array into a string.
![Page 18: Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab: Zip drive dchao Default home page –Default.aspx,](https://reader036.fdocuments.us/reader036/viewer/2022081516/56649d6b5503460f94a4a4a3/html5/thumbnails/18.jpg)
WebClient/Download
Dim wc As New WebClient()
Dim utf8 As New UTF8Encoding()
Dim webData As String
webData = utf8.GetString(wc.DownloadData(txtURL.Text))
txtData.Text = webData
![Page 19: Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab: Zip drive dchao Default home page –Default.aspx,](https://reader036.fdocuments.us/reader036/viewer/2022081516/56649d6b5503460f94a4a4a3/html5/thumbnails/19.jpg)
WebClient/DownloadFile
.Save the dowloaded data directly in a file:
Dim wc As New WebClient()
wc.DownloadFile(txtURL.Text, "c:\testDownLoad.txt")
![Page 20: Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab: Zip drive dchao Default home page –Default.aspx,](https://reader036.fdocuments.us/reader036/viewer/2022081516/56649d6b5503460f94a4a4a3/html5/thumbnails/20.jpg)
WebClient/OpenRead
Dim wc As New WebClient()
Dim stream As Stream
stream = wc.OpenRead(txtURL.Text)
Dim readStream As New StreamReader(stream)
Dim webData As String = readStream.ReadToEnd
txtData.Text = webData
![Page 21: Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab: Zip drive dchao Default home page –Default.aspx,](https://reader036.fdocuments.us/reader036/viewer/2022081516/56649d6b5503460f94a4a4a3/html5/thumbnails/21.jpg)
Hosting Internet Explorer in Windows Forms
• Internet Explorer COM control– Right click Tool Box Windows Form tab and
select Add/Remove Items ….– Select COM Component tab, and Scroll down
to select Microsoft Web Browser.
![Page 22: Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab: Zip drive dchao Default home page –Default.aspx,](https://reader036.fdocuments.us/reader036/viewer/2022081516/56649d6b5503460f94a4a4a3/html5/thumbnails/22.jpg)
Internet Explorer COM control• Events
– DownLoadComplete, DownLoadBegin
• Methods:– Navigate
• Dim HomeURL As String = "http://dchaolaptop"• Private Sub MyBrowser_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
• IE.Navigate(HomeURL)• End Sub
– Note: Navigate can take local file path as input to open a local page.
– Goback, GoForward– Stop– Refresh2– GoHome, GoSearch --- (Go to Microsoft home page and
search engine)
![Page 23: Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab: Zip drive dchao Default home page –Default.aspx,](https://reader036.fdocuments.us/reader036/viewer/2022081516/56649d6b5503460f94a4a4a3/html5/thumbnails/23.jpg)
Web Service
• XML Web Service
• Web services are classes that are stored on the web which can instantiate and use in both Windows and Web applications.
![Page 24: Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab: Zip drive dchao Default home page –Default.aspx,](https://reader036.fdocuments.us/reader036/viewer/2022081516/56649d6b5503460f94a4a4a3/html5/thumbnails/24.jpg)
A Web Service ExampleASPET/TestWebService.ASMX
<%@ WebService Class="CustomerInfo" %>
imports System.Web.Services
imports System
imports System.Data
imports System.Data.Oledb
Public Class CustomerInfo
<webMethod()> public Function GetCname(ByVal CID as String) as String
dim strConn as string ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\sales2k.mdb"
dim objConn as new OledbConnection(strConn)
dim strSQL as string = "select * from customer where CID = '" & CID & "';"
dim objComm as new OledbCommand(strSQL,objConn)
dim Results as string
objConn.open()
dim objDataReader as oledbDataReader
objDataReader=objComm.executeReader()
objDataReader.read()
return objDataReader("Cname")
end function
![Page 25: Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab: Zip drive dchao Default home page –Default.aspx,](https://reader036.fdocuments.us/reader036/viewer/2022081516/56649d6b5503460f94a4a4a3/html5/thumbnails/25.jpg)
Creating a Web Service Using VS
• New Project/ASP.Net Web Service
![Page 26: Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab: Zip drive dchao Default home page –Default.aspx,](https://reader036.fdocuments.us/reader036/viewer/2022081516/56649d6b5503460f94a4a4a3/html5/thumbnails/26.jpg)
Web Service Description Language (WSDL)
• A WSDL file is an XML document containing a complete description of the web service. It shows a web service’s name, methods, and parameter types.
• Help page: After entering web service’s URL, a help page is displayed. You can click the Service Description link to see the WSDL file.
![Page 27: Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab: Zip drive dchao Default home page –Default.aspx,](https://reader036.fdocuments.us/reader036/viewer/2022081516/56649d6b5503460f94a4a4a3/html5/thumbnails/27.jpg)
Consuming Web Services from a Windows Application
• Add a web reference to the web service.
• Declare a web service class variable.– Dim myWebService As New dchaolaptop.CustomerInfo()
• Demo: UseWebService
![Page 28: Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab: Zip drive dchao Default home page –Default.aspx,](https://reader036.fdocuments.us/reader036/viewer/2022081516/56649d6b5503460f94a4a4a3/html5/thumbnails/28.jpg)
Universal Description, Discovery, and Integration (UDDI)
• A directory service for web services.– http://uddi.org
![Page 29: Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab: Zip drive dchao Default home page –Default.aspx,](https://reader036.fdocuments.us/reader036/viewer/2022081516/56649d6b5503460f94a4a4a3/html5/thumbnails/29.jpg)
Simple Mail Transport Protocol (SMTP)
• Email messages are text files.• InetPub\MailRoot
– PickUp directory: • SMTP monitors this directory and sends any messages found
in this directory.
– Drop:• Incoming messages received by SMTP are written to this
directory.
– BadMail:• If an email cannot be delivered or returned to the sender it is
moved to this directory.
![Page 30: Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab: Zip drive dchao Default home page –Default.aspx,](https://reader036.fdocuments.us/reader036/viewer/2022081516/56649d6b5503460f94a4a4a3/html5/thumbnails/30.jpg)
ASP.Net Email Classes
• SmtpMail class– System.Web.Mail– System.Web.Mail.MailMessage
• Methods:– Send(From, To, Subject, messageText)
• SmtpMail.Send(TextBox1.Text, TextBox2.Text, TextBox3.Text, TextBox4.Text)
– Send(System.Web.Mail.MailMessage)• Demo:
– SendMail.aspx– Import system.web.mail
![Page 31: Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab: Zip drive dchao Default home page –Default.aspx,](https://reader036.fdocuments.us/reader036/viewer/2022081516/56649d6b5503460f94a4a4a3/html5/thumbnails/31.jpg)
Using MailMessage Class to Set Email Properties
• Email properties:– Attachments– Bcc– Body– BodyFormat
• Text or Html
– Cc– From– Headers– Subject– To
![Page 32: Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\ –Computer lab: Zip drive dchao Default home page –Default.aspx,](https://reader036.fdocuments.us/reader036/viewer/2022081516/56649d6b5503460f94a4a4a3/html5/thumbnails/32.jpg)
Using MailMessage with Attachment
Dim objMsg As New MailMessage objMsg.From = TextBox1.Text objMsg.To = TextBox2.Text objMsg.Subject = TextBox3.Text objMsg.Body = TextBox4.Text Dim attachment As MailAttachment = New MailAttachment("c:\paradise.jpg") objMsg.Attachments.Add(attachment) Try SmtpMail.Send(objMsg) Catch ex As SystemException MessageBox.Show(ex.Message) End Try