CIS 451: Introduction to ASP.NET

3,600 views

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,600
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
14
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • http://134.71.196.107/westfall/
  • Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim intI As Integer Dim output As String = "" For intI = 1 To 7 output += "<font size = " & intI & ">" _ & "Size is " & intI & "</font><br>" Next Label1.Text = output End Sub
  • CIS 451: Introduction to ASP.NET

    1. 1. CIS 451: Introduction to ASP.NET Dr. Ralph D. Westfall January, 2009
    2. 2. Web Development Problem <ul><li>HTML designed to display static pages </li></ul><ul><ul><li>only interactive when user clicks links </li></ul></ul><ul><ul><ul><li>can’t provide animation </li></ul></ul></ul><ul><ul><ul><ul><li>except animated GIFs </li></ul></ul></ul></ul><ul><ul><ul><li>can’t create custom pages for specific types of customers </li></ul></ul></ul><ul><ul><li>can’t use databases, spreadsheets, etc. </li></ul></ul><ul><ul><li>no security capabilities in HTML itself </li></ul></ul><ul><ul><ul><li>except hiding passwords <input type=&quot;password&quot; etc. </li></ul></ul></ul><ul><ul><ul><li>using long directory/file names works somewhat, but it's not HTML </li></ul></ul></ul>
    3. 3. Solution 1: Client Side Scripts <ul><li>JavaScript (dominant product) can do </li></ul><ul><ul><li>animation, rollovers , message boxes </li></ul></ul><ul><ul><li>calculations , validation of user inputs </li></ul></ul><ul><ul><li>incorporate customized content into pages </li></ul></ul><ul><ul><ul><li>e.g. based on day/time, user inputs, etc. </li></ul></ul></ul><ul><ul><li>provide limited access to user’s system </li></ul></ul><ul><ul><ul><li>system date, browser, plug-in information </li></ul></ul></ul><ul><ul><ul><li>set cookies (data for server for next visit) </li></ul></ul></ul>
    4. 4. Client Side Scripts (continued) <ul><li>what (client side) JavaScript can’t do </li></ul><ul><ul><li>connect with databases, and possibly other applications on the server </li></ul></ul><ul><ul><li>provide meaningful security for </li></ul></ul><ul><ul><ul><li>access control (but JavaScript Source has some &quot;hackish&quot; scripts) </li></ul></ul></ul><ul><ul><ul><li>hiding proprietary code if it's in the HTML file or user has a tool to find it (e.g., Web Developer add-on for Firefox) </li></ul></ul></ul>
    5. 5. Solution 2: Server Side Scripts <ul><li>use common gateway interface ( CGI ) </li></ul><ul><li>offer database & security capabilities </li></ul><ul><li>written in C, C++, Perl, etc. </li></ul><ul><ul><li>relatively difficult to program & maintain </li></ul></ul><ul><li>use server resources relatively inefficiently </li></ul><ul><li>separate programs in addition to HTML </li></ul><ul><ul><li>but this is probably an advantage </li></ul></ul>
    6. 6. Solution 3: ASP <ul><li>Active Server Pages </li></ul><ul><li>released by Microsoft in 1996 </li></ul><ul><li>works with Microsoft servers </li></ul><ul><ul><li>Windows Server 2008 </li></ul></ul><ul><ul><li>free Visual Web Developer Express 2008 IDE includes a lightweight personal web server for developing ASP.NET applications </li></ul></ul><ul><ul><li>so does Visual Studio </li></ul></ul>
    7. 7. Solution 3: ASP (continued) <ul><li>simple language </li></ul><ul><li>can go in same files as HTML code </li></ul><ul><li>provides many of the capabilities of CGI </li></ul><ul><li>uses server resources more efficiently than CGI </li></ul><ul><li>using ASP server extensions, can work with non-Microsoft servers, but … </li></ul>
    8. 8. ASP.NET <ul><li>major revision of ASP </li></ul><ul><ul><li>can use different languages, not just VB.NET </li></ul></ul><ul><ul><ul><li>VB.NET code looks more like Java than the VBScript used previously </li></ul></ul></ul><ul><ul><li>.NET code is compiled into MSIL (Microsoft Intermediate Language) </li></ul></ul><ul><ul><li>MSIL is then interpreted into machine language that runs on the server </li></ul></ul>
    9. 9. ASP.NET: Many Languages <ul><li>HTML (of course!) </li></ul><ul><li>Visual Basic.NET </li></ul><ul><li>can also use C# and J# with VWDX </li></ul><ul><li>.NET supports over 30 other languages </li></ul><ul><ul><li>C++ and JScript (Microsoft's version of JavaScript) work with Visual Studio.NET </li></ul></ul><ul><ul><li>other (non Microsoft) languages can also work with Visual Studio.NET </li></ul></ul>
    10. 10. Tools To Develop & Use ASP.NET <ul><li>a tool to create code </li></ul><ul><ul><li>text editors: Notepad, TextPad, etc. </li></ul></ul><ul><ul><li>HTML authoring tools: Dreamweaver, FrontPage, etc. </li></ul></ul><ul><ul><li>Visual Studio.NET, Web Matrix or Visual Web Developer Express 2008 (free!) </li></ul></ul><ul><li>IIS or VWDX on your computer </li></ul><ul><ul><li>or free 14-day ASP.NET hosting </li></ul></ul><ul><li>web browser </li></ul>
    11. 11. Creating an ASP.NET Page <ul><li>create an HTML document </li></ul><ul><li>add ASP code in appropriate places </li></ul><ul><li>save with extension of .aspx </li></ul><ul><li>if don't have local server on computer, upload to a remote ASP.NET server </li></ul><ul><ul><li>Cal Poly Intranet server won't run ASP </li></ul></ul><ul><li>view in browser (file can be on local machine with server or remote server) </li></ul>
    12. 12. Simple ASP.NET Page (not Visual Studio) <ul><li>create a document with HTML code </li></ul><ul><li>add .NET code within HTML (inline) </li></ul><ul><ul><li>at top, need </li></ul></ul><ul><ul><li><%@ Page Language=&quot;VB&quot; %> </li></ul></ul><ul><li>save with extension of .aspx </li></ul><ul><li>upload to remote server (if don't have Web Matrix or IIS) or paste into VS </li></ul><ul><li>view in browser </li></ul>
    13. 13. hello.aspx <ul><ul><li><%@ Page Language=&quot;VB&quot; %> </li></ul></ul><ul><ul><li><html> </li></ul></ul><ul><ul><li><body> <!-- paste below </form> tag--> </li></ul></ul><ul><ul><li><% </li></ul></ul><ul><ul><li>Response.Write(&quot;<P>Hello, world!&quot;) </li></ul></ul><ul><ul><li>%> </li></ul></ul><ul><ul><li><P>The time is: <% = Now() %> </li></ul></ul><ul><ul><li></body> </li></ul></ul><ul><ul><li></html> <!-- View Source in browser --> </li></ul></ul>
    14. 14. ASP.NET Coding within HTML <ul><li>use <% at start, %> at end </li></ul><ul><li>on same line (inline) </li></ul><ul><li><% = Time %> </li></ul><ul><li>or on multiple lines (block) </li></ul><ul><ul><li><% </li></ul></ul><ul><ul><li>Response.Write &quot;<P>Hello, world!&quot; </li></ul></ul><ul><ul><li>Response.Write 'like VB.NET Debug.Write </li></ul></ul><ul><ul><li>%> </li></ul></ul>
    15. 15. ASP.NET Output in HTML <ul><li>ASP inside a HTML tag </li></ul><ul><ul><li><P>The time is: <% = Time %> </li></ul></ul><ul><ul><li>use <% = followed by a variable or a function that returns data, then %> </li></ul></ul><ul><ul><li>variable can come from server itself, or from client machine, or can be defined in code elsewhere in same or another ASP file </li></ul></ul><ul><ul><li><% Dim strCar as String=&quot;Geo&quot; %> <P>The car is: <% = strCar %> </li></ul></ul>
    16. 16. Generating ASP Output - 2 <ul><li>ASP.NET code can write text and also data from ASP.NET variables </li></ul><ul><ul><li>hit counter example </li></ul></ul><ul><ul><li><% </li></ul></ul><ul><ul><li>nHits = nHits + 1 </li></ul></ul><ul><ul><li>Response.Write &quot;Hits = &quot; & nHits </li></ul></ul><ul><ul><ul><ul><ul><li>'text variable </li></ul></ul></ul></ul></ul><ul><ul><li>%> </li></ul></ul>
    17. 17. Generating ASP Output - 3 <ul><li>can mix text, HTML, and ASP.NET variables in code </li></ul><ul><ul><li>this includes using ASP to write HTML tags, in addition to writing variables and text </li></ul></ul>
    18. 18. fontsize.aspx <ul><li><% </li></ul><ul><li>Dim intI as Integer </li></ul><ul><li>For intI = 1 to 7 </li></ul><ul><li>%> <!-HTML inside ASP loop-> </li></ul><ul><li><font size = <% = intI %> > </li></ul><ul><li>Size is <% = intI %> </font><br/> </li></ul><ul><li><% Next %> <!-note-> </li></ul><ul><li><!-what will you see from this?-> </li></ul><ul><li><!-fontcolor.aspx 'notes-> </li></ul>
    19. 19. Using ASP.NET with Forms <ul><li>use HTML or ASP page to create a form </li></ul><ul><ul><li>be sure all form fields have id = &quot;[ ]&quot; and also name = &quot;[ ]&quot; 'same as for id= </li></ul></ul><ul><li>use an ASP.NET page to process inputs </li></ul><ul><ul><li>action attribute in form has name of an ASP.NET file, and use Input (Submit) button </li></ul></ul><ul><li>form field values accessible to ASP as </li></ul><ul><li>Request.QueryString(&quot;[form field name]&quot;) </li></ul>
    20. 20. form2.html <ul><li><html><body> </li></ul><ul><li><form method=&quot;get&quot; </li></ul><ul><li>action=&quot;resp2.aspx&quot;> </li></ul><ul><li>Last Name <input type=&quot;text&quot; </li></ul><ul><li>name=&quot;custName&quot; id=&quot;custName&quot;> </li></ul><ul><li></body></html> </li></ul><ul><li><!--need to refresh?--> </li></ul>
    21. 21. Default.aspx <ul><li><%@ Page Language=&quot;VB&quot; %> </li></ul><ul><li><html><body> </li></ul><ul><li>Input from form: </li></ul><ul><li><% </li></ul><ul><li>Dim strCustName as String </li></ul><ul><ul><li>strCustName = _ </li></ul></ul><ul><ul><li>Request.QueryString(&quot;custName&quot;) </li></ul></ul><ul><li>Response.Write(&quot;last name is &quot; & _ </li></ul><ul><li>strCustName) </li></ul><ul><li>%></body></html> </li></ul>
    22. 22. Using ASP.NET with Forms - 2 <ul><li>if have more than just one text field, must have a Submit button on form </li></ul><ul><li><input type=submit [etc.]> </li></ul><ul><li>after development would use </li></ul><ul><li><form method=&quot;post&quot; [etc.]> </li></ul><ul><ul><li>when using post, also need to change every Request.QueryString to Request.Form in the ASP page identified by the action </li></ul></ul>
    23. 23. Using Visual Studio.NET for ASP <ul><li>using Visual Studio.NET or Visual Web Developer Express 2008 </li></ul><ul><ul><li>Create: Web Site… ASP.NET Web Site </li></ul></ul><ul><ul><li>add a Label to Default.aspx designer and expand it vertically and horizontally to occupy 25% of the screen </li></ul></ul><ul><ul><li>double click the screen (outside of the label) to start a Page_Load Sub </li></ul></ul><ul><ul><li>paste code on following page into Sub </li></ul></ul>
    24. 24. VB.NET Web Code <ul><li>Dim i As Integer </li></ul><ul><li>Dim colr() As String = {&quot;000000&quot;, &quot;333300&quot;, _ &quot;666600&quot;, &quot;999900&quot;, &quot;cccc00&quot;, &quot;ffff00&quot;} </li></ul><ul><li>Dim output As String = &quot;&quot; </li></ul><ul><li>For i = 0 To 5 </li></ul><ul><li>output &= &quot;<h1><font color=#&quot; & colr(i) _ </li></ul><ul><li>& &quot;>&quot; & colr(i) & &quot;</font></h1>&quot; </li></ul><ul><li>Next </li></ul><ul><li>Label1.Text = output </li></ul>
    25. 25. Run Code <ul><li>click Start </li></ul><ul><li>(first time) modify the web.config…>OK </li></ul><ul><li>view code and then make changes as necessary </li></ul>
    26. 26. ASP.NET Code Samples <ul><li>CIS 451 ASP Code Samples </li></ul><ul><li>W3 Schools online tutorials and demonstration code </li></ul>

    ×