ASP.NET 2.0 Chapter 5 Advanced Web Controls
ASP.NET 2.0, Third Edition2 Objectives
ASP.NET 2.0, Third Edition3 AdRotator Contrtol The AdRotator control allows you to display a banner ad on a web page The advertisement file, also known as the rotation file, is an XML document that stores the ad information –Inside this file is indicated the amount of time each ad is seen on the web page The banner ad is a hyperlinked image
ASP.NET 2.0, Third Edition4 The Role of the Advertisement File The advertisement file contains: –Information to create the HTML image tag to insert the image into the web page –Information that creates the hyperlink using an anchor tag Each time the page is displayed, the AdRotator class retrieves a different image and hyperlink Contained within the Advertisements node are one or more Ad Elements –Ad elements contain individual properties for the Ad (i.e. location, URL, alternate text, height, and width)
ASP.NET 2.0, Third Edition5 The Calender Control The Calendar control is used to insert and configure an interactive calendar within the web page The calendar can be used to show event data such as the location and time of the event The Calendar control is created by the calendar class, System.WebControls.Calendar To insert the calendar into the web page: –
ASP.NET 2.0, Third Edition6 Supported Properties, Methods, and Events A style can be assigned to the calendar using a class defined in the CSSClass property There are various Calendar control style properties –(i.e. DayHeaderStyle, Title Style, TodayDayStyle) Other properties allow the modification of the Calendar control’s appearance –(i.e. ShowDayHeader property and ShowGridLines property) You can write different event handlers to intercept events and execute your own custom code
ASP.NET 2.0, Third Edition7 Using the FileUpload Control The FileUpload control allows you to upload a file to a web server The file upload capability is completely built into the ASP.NET runtime and available to all ASP.NET applications without third-party file upload components The key to building an upload feature into your web site is the FileUpload control, which is a Web control –The FileUpload control class is the System.Web.UI.WebControls.FileUpload
ASP.NET 2.0, Third Edition8 Uploading a File with FileUpload Control The FileUpload control, created with the tag, allows users to browse their file system and locate their file You always should verify the users’ credentials before allowing them to upload the file The FileUpload control contains several properties that you may access before you upload the file: –HasFile Property –FileName Property –FileBytes Property –FileContent Property
ASP.NET 2.0, Third Edition9 Sending from the Web Pages Often you will want to generate a customized automated reply that uses form data To send outbound from a web page, you must use an server, along with an object or application, to communicate with the e- mail server
ASP.NET 2.0, Third Edition10 Security and Privacy Issues Related to ing is the process of sending messages through servers A major issue related to is spam –Spam is unauthorized delivery of messages –Because there is virtually no cost to deliver spam, it is commonly used as a marketing tool to attract customers –Some spam poses as legitimate and uses hyperlinks to lure end users onto web sites that download viruses and steal information such as passwords, bank account numbers, and credit card information
ASP.NET 2.0, Third Edition11 The Role of the Server Web developers must ensure that their web applications do not allow unauthorized users to send through their web application or server The server, known as the SMTP server, is included when you install the IIS web server Simple Mail Transfer Protocol (SMTP) is a protocol, or set of rules, used to transfer mail between servers –The SMTP server contains several folders (i.e. Pickup, Queue, Badmail, Drop Route, & Mailbox)
ASP.NET 2.0, Third Edition12 Configuring the Server Microsoft Management Console (MMC) is the main interface to the administrative programs such as IIS and SMTP –Messages property page – configures the size of the message and the session size –Delivery property page – configures how the message is delivered –Outbound Security tab – configures a different user account to send mail messages; you can use the anonymous account, or authenticate the user with basic authentication or Windows authentication –Outbound Connections tab – limits the number of outbound messages, the time-out property, and the number of connections per domain –Advanced tab – configures which servers can access the Default SMTPVirtual Server to send or relay messages –Security tab – accesses and changes the SMTP settings
ASP.NET 2.0, Third Edition13 CDONTS and Objects CDONTS is a component provided with the SMTP server to allow third-party applications, such as ASP.NET, to communicate with the SMTP server –CDONTS and SMTP service are only available with Windows Server and Windows XP Professional You will use the objects to create and place your message in the Pickup folder The receiving mail server may accept or reject the message –Commonly rejected because the user’s mailbox is full or the user is not a valid user account
ASP.NET 2.0, Third Edition14 Storing and Retrieving Data in the Web Server’s File System There are several classes and objects within the System.IO namespace that allow you to interact with the web server’s file system The System.IO namespace contains several classes, such as File, FileStream, and Directory, that allow you to create, read, and delete files –FileSystemInfo class is the base class for both the FileInfo class and the DirectoryInfo class –DirectoryInfo class allows you to obtain the properties of a directory and its subdirectories –FileInfo class allows you access to the Attribute properties of a file
ASP.NET 2.0, Third Edition15 Working with Directories and the DirectoryInfo Class
ASP.NET 2.0, Third Edition16 Working with Directories and the DirectoryInfo Class (continued)
ASP.NET 2.0, Third Edition17 Working with Directories and the DirectoryInfo Class (continued)
ASP.NET 2.0, Third Edition18 Creating and Deleting Directories with the DirectoryInfo Class
ASP.NET 2.0, Third Edition19 Creating and Deleting Directories with the DirectoryInfo Class (continued)
ASP.NET 2.0, Third Edition20 Security Issues Related to Building Web Applications Many times, company employees don’t know the possibilities or the implications of building web sites –You may need to provide them with suggestions on how to use and how to secure the web site As you design your web sites, you should know the following: –You can create a login form processed by ASP.NET for web applications. –JavaScripts run on the client and are not adequate for securing a web site –The login method needs to be combined with other security methods –Access is useful in situations such as displaying non-secure information because hackers can use password detection programs to hack into the file –An end user can right-click a graphic on your page and save the image locally
ASP.NET 2.0, Third Edition21 Summary ASP.NET controls enhance the user interface and increase interactivity within web pages. Examples of ASP.NET controls are the AdRotator control and the Calendar control. The AdRotator control allows you to display rotating banner ads. The banner contains a hyperlink, alternate text, and an image. If you do not specify the height and width, you can display images of varying sizes. –The advertisement file is an XML file that is used to store the ad information. The advertisement file can be edited with a text editor, such as Notepad, or an XML editor. The Calendar control displays an interactive calendar. You can use many properties to format the calendar. You can retrieve the value of the date that users click, or execute code when they click a particular date.
ASP.NET 2.0, Third Edition22 Summary (continued) The File Input control is an HTML Server control that allows you to browse your network to locate a file to upload file to a web server. The FileUpload control is a Web server control that also allows you to browse your network to locate a file to be uploaded to the web server. On the web server, you must retrieve the file name. You can change the file name or path on the server in the code behind the page. The SaveAs method saves the file to the web server. The SMTP server is the default mail service that is installed with the Internet Information Service web server. The mail server’s default root directory is C:\Inetpub\MailRoot\. The Pickup folder is used to store outgoing mail messages. Mail that cannot be delivered is sent to the BadMail directory. You can configure the SMTP server via the property sheets in the MMC application.
Summary (continued) The System.IO namespace provides you with classes that interact with the web server’s file system. It contains several classes such as File, FileStream, and Directory, which allow you to create, read, and delete files. The newer classes, named DirectoryInfo and FileInfo, are more flexible and provide easier access to the file system. ASP.NET 2.0, Third Edition23