Module 11: Internet Access. Overview Internet Application Scenarios The WebRequest and WebResponse Model Application Protocols Handling Errors Security.

Slides:



Advertisements
Similar presentations
Enabling Secure Internet Access with ISA Server
Advertisements

Introduction to Sockets Jan Why do we need sockets? Provides an abstraction for interprocess communication.
Categories of I/O Devices
Hypertext Transfer PROTOCOL ----HTTP Sen Wang CSE5232 Network Programming.
Module 5: TLS and SSL 1. Overview Transport Layer Security Overview Secure Socket Layer Overview SSL Termination SSL in the Hosted Environment Load Balanced.
Module 10: Troubleshooting Network Access. Overview Troubleshooting Network Access Resources Troubleshooting LAN Authentication Troubleshooting Remote.
Module 5: Configuring Access to Internal Resources.
Hypertext Transfer Protocol Kyle Roth Mark Hoover.
1 Java Networking – Part I CS , Spring 2008/9.
2: Application Layer1 Socket Programming. 2: Application Layer2 Socket-programming using TCP Socket: a door between application process and end- end-transport.
Application Layer. Domain Name System Domain Name System (DNS) Problem – Want to go to but don’t know the IP addresswww.google.com Solution.
Rensselaer Polytechnic Institute CSC-432 – Operating Systems David Goldschmidt, Ph.D.
1 Enabling Secure Internet Access with ISA Server.
Managing Client Access
IT 210 The Internet & World Wide Web introduction.
Internet Protocols & Client Server Programming
Dr. John P. Abraham Professor University of Texas Pan American Internet Applications and Network Programming.
Session 11: Security with ASP.NET
Computer Networks  Network - A system of computers interconnected in order to share information.  Data transmission - consists of sending and receiving.
Human-Computer Interface Course 5. ISPs and Internet connection.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
Session 10 Windows Platform Eng. Dina Alkhoudari.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
HyperText Transfer Protocol (HTTP).  HTTP is the protocol that supports communication between web browsers and web servers.  A “Web Server” is a HTTP.
HTTP The HyperText Transfer Protocol. Objectives Introduce HTTP Introduce HTTP support in.NET.
Implementing ISA Server Publishing. Introduction What Are Web Publishing Rules? ISA Server uses Web publishing rules to make Web sites on protected networks.
Sistem Jaringan dan Komunikasi Data #9. DNS The Internet Directory Service  the Domain Name Service (DNS) provides mapping between host name & IP address.
Chapter 1: Introduction to Web Applications. This chapter gives an overview of the Internet, and where the World Wide Web fits in. It then outlines the.
Lesson №12 Telecommunication network software design for HTTP and Internet Lector: Aliev H.U. TASHKENT UNIVERSITY OF INFORMATION TECHNOLOGIES THE DEPARTMENT.
Lector: Aliyev H.U. Lecture №6 Design of client-server communication software. TCP-based network programming TASHKENT UNIVERSITY OF INFORMATION TECHNOLOGIES.
Windows Programming Using C# Internet Programming.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Securing a Microsoft ASP.NET Web Application.
Server Sockets: A server socket listens on a given port Many different clients may be connecting to that port Ideally, you would like a separate file descriptor.
Module 4: Configuring ISA Server as a Firewall. Overview Using ISA Server as a Firewall Examining Perimeter Networks and Templates Configuring System.
Network Programming Chapter 3: Network Programming in.NET.
Internet Applications and Network Programming Dr. Abraham Professor UTPA.
The Inter-network is a big network of networks.. The five-layer networking model for the internet.
Dr. John P. Abraham Professor University of Texas Pan American Internet Applications and Network Programming.
Web Client-Server Server Client Hypertext link TCP port 80.
Chapter 2 Applications and Layered Architectures Sockets.
Module 6: Managing Client Access. Overview Implementing Client Access Servers Implementing Client Access Features Implementing Outlook Web Access Introduction.
Module 7: Advanced Application and Web Filtering.
Socket Programming Lab 1 1CS Computer Networks.
12/5/2015.net 1 system.net Contains any network functionallity you would need in c# Several sub namespaces exists to allow for more fined control –System.Net.Sockets.
Protocols COM211 Communications and Networks CDA College Olga Pelekanou
The Client-Server Model And the Socket API. Client-Server (1) The datagram service does not require cooperation between the peer applications but such.
27.1 Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Overview of Servlets and JSP
UNIT - III WEB SERVICES BUILDING BLOCKS. Transport protocols for web services Transport such as HTTP and TCP are becoming common for SOAP traffic. However.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
Network Programming. These days almost all devices.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics Advanced.NET Programming I 14 th Lecture Pavel Ježek
HTTP – An overview.
Computing with C# and the .NET Framework
The HyperText Transfer Protocol
Client/Server Example
Transport Protocols Relates to Lab 5. An overview of the transport protocols of the TCP/IP protocol suite. Also, a short discussion of UDP.
HTTP Hypertext Transfer Protocol
Process-to-Process Delivery:
Internet Applications and Network Programming
.Net Sockets.
Visual Programming COMP-315
HTTP Hypertext Transfer Protocol
Process-to-Process Delivery: UDP, TCP
Jim Fawcett CSE681 – Software Modeling & Analysis Fall 2008
Advanced .NET Programming I 15th Lecture
Exceptions and networking
Jim Fawcett CSE681 – Software Modeling & Analysis Fall 2008
Jim Fawcett CSE681 – Software Modeling & Analysis Fall 2008
Presentation transcript:

Module 11: Internet Access

Overview Internet Application Scenarios The WebRequest and WebResponse Model Application Protocols Handling Errors Security Best Practices

Internet Application Scenarios Server-Side ASP.NET Applications Obtain data from back-end sources for a browser request Peer-to-Peer Applications Send and receive data by acting as servers and clients Client Applications That Periodically Access the Network A robust implementation of HTTP 1.1, including: Pipelining, chunking, authentication, pre-authentication, encryption, proxy support, server certificate validation, and connection management

 The WebRequest and WebResponse Model Uniform Resource Identifier NetworkStream Class Creating a WebRequest Invoking a WebRequest Sending Data Receiving Data Using the WebRequest and WebResponse Model

Uniform Resource Identifier URI Contains: Scheme identifier – specifies protocol to be used Server identifier – specifies DNS name or TCP address Path identifier – specifies location on the server Optional query string – provides additional request information Example: Scheme identifier – http Server identifier – Path identifier – /whatsnew.aspx Query String – ?date=today

NetworkStream Class A NetworkStream Object Provides: A Way to Send and Receive All Types of Web Data Methods That Are Compatible with Other.NET Streams Processing of Data As It Arrives System.Text.Encoding – Characters from and to Bytes Sequential Blocks Use StreamReader and StreamWriter // reading ASCII stream to string Byte[] read = new Byte[32]; int bytes = anASCIIStream1.Read(read, 0, read.Length); string stringData = Encoding.ASCII.GetString(read); // writing string to ASCII stream Byte[] asciiBytes = Encoding.ASCII.GetBytes(stringData); anASCIIStream2.Write(asciiBytes, asciiBytes.Length, 0); // reading ASCII stream to string Byte[] read = new Byte[32]; int bytes = anASCIIStream1.Read(read, 0, read.Length); string stringData = Encoding.ASCII.GetString(read); // writing string to ASCII stream Byte[] asciiBytes = Encoding.ASCII.GetBytes(stringData); anASCIIStream2.Write(asciiBytes, asciiBytes.Length, 0);

Creating a WebRequest The WebRequest Encapsulates Details of Request Created by calling WebRequest.Create method Set any property values that are required Cast to access protocol-specific features WebRequest req = WebRequest.Create(" WebRequest req = WebRequest.Create(" HttpWebRequest httpReq = (HttpWebRequest) WebRequest.Create(" // Turn off connection keep-alives. httpReq.KeepAlive = false; HttpWebRequest httpReq = (HttpWebRequest) WebRequest.Create(" // Turn off connection keep-alives. httpReq.KeepAlive = false; req.Credentials = new NetworkCredential("username","password"); req.Credentials = new NetworkCredential("username","password");

Invoking a WebRequest Request Is Made by Calling the GetResponse Method Cast to access HTTP-specific features WebResponse resp = req.GetResponse(); HttpWebResponse httpResp = (HttpWebResponse)httpReq.GetResponse(); //Get the HTTP content length returned by the server. String contentLength = httpResp.ContentLength.ToString(); HttpWebResponse httpResp = (HttpWebResponse)httpReq.GetResponse(); //Get the HTTP content length returned by the server. String contentLength = httpResp.ContentLength.ToString();

Sending Data For Requests That Send Data to the Server //... try { byte[] sendData = Encoding.ASCII.GetBytes("some data"); int sendLength = sendData.Length; HttpWebRequest httpReq = (HttpWebRequest) WebRequest.Create( " httpReq.Method = "POST"; httpReq.ContentLength = sendLength; Stream sendStream = httpReq.GetRequestStream(); sendStream.Write(sendData,0,sendLength); sendStream.Close(); } catch(Exception e) {//...} //... //... try { byte[] sendData = Encoding.ASCII.GetBytes("some data"); int sendLength = sendData.Length; HttpWebRequest httpReq = (HttpWebRequest) WebRequest.Create( " httpReq.Method = "POST"; httpReq.ContentLength = sendLength; Stream sendStream = httpReq.GetRequestStream(); sendStream.Write(sendData,0,sendLength); sendStream.Close(); } catch(Exception e) {//...} //...

Receiving Data Reading Response Data // Get the response stream. Stream respstrm = resp.GetResponseStream(); // Create a buffer to hold the response data. int BufferSize = 512; Byte[] Buffer = new Byte[BufferSize]; // Read the stream to access the data. int bytesRead = respstrm.Read(Buffer, 0, BufferSize); while (bytesRead > 0) { Console.Write( Encoding.ASCII.GetString(Buffer, 0, bytesRead)); bytesRead = respstrm.Read(Buffer, 0, BufferSize); } respstrm.Close(); // Get the response stream. Stream respstrm = resp.GetResponseStream(); // Create a buffer to hold the response data. int BufferSize = 512; Byte[] Buffer = new Byte[BufferSize]; // Read the stream to access the data. int bytesRead = respstrm.Read(Buffer, 0, BufferSize); while (bytesRead > 0) { Console.Write( Encoding.ASCII.GetString(Buffer, 0, bytesRead)); bytesRead = respstrm.Read(Buffer, 0, BufferSize); } respstrm.Close();

Using the WebRequest and WebResponse Model //... WebRequest wReq = WebRequest.Create (" WebResponse wResp = wReq.GetResponse(); // Get a readable stream from the server StreamReader sr = new StreamReader( wResp.GetResponseStream(),Encoding.ASCII); int length = 1024; char[] Buffer = new char[1024]; int bytesread = 0; //Read from the stream and write data to console bytesread = sr.Read( Buffer, 0, length); while( bytesread > 0 ) { Console.Write( Buffer,0, bytesread); bytesread = sr.Read( Buffer, 0, length); } //Close the stream when finished sr.Close(); //... WebRequest wReq = WebRequest.Create (" WebResponse wResp = wReq.GetResponse(); // Get a readable stream from the server StreamReader sr = new StreamReader( wResp.GetResponseStream(),Encoding.ASCII); int length = 1024; char[] Buffer = new char[1024]; int bytesread = 0; //Read from the stream and write data to console bytesread = sr.Read( Buffer, 0, length); while( bytesread > 0 ) { Console.Write( Buffer,0, bytesread); bytesread = sr.Read( Buffer, 0, length); } //Close the stream when finished sr.Close(); //...

 Application Protocols HTTP Internet Domain Name System TCP and UDP Sockets

HTTP Classes That Provide HTTP and HTTPS Protocols HttpWebRequest and HttpWebResponse Support Most HTTP 1.1 features HTTP Redirects Automatically if AllowAutoRedirect Property Is true (the Default) Use ServicePoint, ServicePointManager, and ConnectGroupName Classes to Manage Connections

Internet Domain Name System Dns Class Retrieves Data About a Host from DNS GetHostByName query for Resolve query for IPHostEntry hostInfo = Dns.GetHostByName(" IPHostEntry hostInfo = Dns.GetHostByName(" IPHostEntry hostInfo = Dns.Resolve(" IPHostEntry hostInfo = Dns.Resolve("

TCP and UDP TCP Client Connecting to a Server/Listener TCP Server/Listener Monitors Port for Clients TcpClient tcpc = new TcpClient(serverURI, 13); Stream s = tcpc.GetStream(); Byte[] read = new Byte[32]; int bytes = s.Read(read, 0, read.Length); String strInData = Encoding.ASCII.GetString(read); TcpClient tcpc = new TcpClient(serverURI, 13); Stream s = tcpc.GetStream(); Byte[] read = new Byte[32]; int bytes = s.Read(read, 0, read.Length); String strInData = Encoding.ASCII.GetString(read); TcpListener tcpl = new TcpListener(13); tcpl.Start(); while (!done){ // Accept will block until someone connects Socket s = tcpl.AcceptSocket(); //Code to handle request goes here } tcpl.Stop(); TcpListener tcpl = new TcpListener(13); tcpl.Start(); while (!done){ // Accept will block until someone connects Socket s = tcpl.AcceptSocket(); //Code to handle request goes here } tcpl.Stop();

Sockets System.Net Classes Are Built on System.Net.Sockets System.Net.Sockets Are Based on the WinSock32 API See Example in Student Notes

Handling Errors A WebException Can Be Thrown by GetResponse Has Status property, value from WebExceptionStatus If WebExceptionStatus.ProtocolError, then WebResponse contains protocol error information try { //... Create a request, get response and process stream. } catch (WebException webExcp) { Console.WriteLine("A WebException has been caught"); Console.WriteLine(webExcp.ToString()); WebExceptionStatus status = webExcp.Status; if (status == WebExceptionStatus.ProtocolError) { Console.Write( "The server returned protocol error "); Console.WriteLine(webExcp.Response.ToString()); } catch (Exception e) {// Code to catch other exceptions goes here.} try { //... Create a request, get response and process stream. } catch (WebException webExcp) { Console.WriteLine("A WebException has been caught"); Console.WriteLine(webExcp.ToString()); WebExceptionStatus status = webExcp.Status; if (status == WebExceptionStatus.ProtocolError) { Console.Write( "The server returned protocol error "); Console.WriteLine(webExcp.Response.ToString()); } catch (Exception e) {// Code to catch other exceptions goes here.}

 Security Web Proxy Secure Sockets Layer Internet Authentication Permissions

Web Proxy Global Proxy for All Web Requests Proxy named webproxy using port 80 Overriding the Global Proxy Setting Request uses proxy named alternateproxy and port 80 WebProxy proxyObject = new WebProxy( " GlobalProxySelection.Select = proxyObject; WebProxy proxyObject = new WebProxy( " GlobalProxySelection.Select = proxyObject; WebRequest req = WebRequest.Create( " req.Proxy = new WebProxy( " WebRequest req = WebRequest.Create( " req.Proxy = new WebProxy( "

Secure Sockets Layer SSL Is Used Automatically If the URI Begins with https String MyURI = " WebRequest wReq = WebRequest.Create(MyURI); String MyURI = " WebRequest wReq = WebRequest.Create(MyURI);

Internet Authentication.NET Supports Various Kinds of Authentication Basic, digest, negotiate, NTLM, and Kerberos authentication Users can also create their own authentication Credentials Stored in Classes NetworkCredential – for a single Internet resource CredentialCache – for multiple Internet resources Authentication Managed by the AuthenticationManager Some Schemes Allow Pre-Authentication to Save Time

Permissions WebPermissions Controls an application's right to request data from a URI or to serve a URI to the Internet SocketPermissions Controls an application's right to accept data on a local port or to contact applications Choose Permission Class Based on Application Use WebRequest and its descendents use WebPermissions Socket-level access uses SocketPermissions Both Classes Support Two Kinds of Permissions Accept – application can answer an incoming connection Connect – application can initiate a connection

Best Practices When Possible, Use WebRequest and WebResponse, Instead of Protocol-Specific Subclasses For Better Performance, Use Asynchronous Methods Tune Performance by Adjusting the Number of Connections ConnectionLimit property in the ServicePoint instance When Possible, Use TcpClient or UdpClient, Instead of Writing Directly to a Socket Use the CredentialCache Class If Credentials Are Required

Lab 11: Creating a DateTime Client/Server Application

Review Internet Application Scenarios The WebRequest and WebResponse Model Application Protocols Handling Errors Security Best Practices