ASP.NET Tips and Tricks - PowerPoint PPT Presentation

Loading...

PPT – ASP.NET Tips and Tricks PowerPoint presentation | free to download - id: 89aa-MjkxN



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

ASP.NET Tips and Tricks

Description:

ASP.NET Tips and Tricks. Russ Fustino. Microsoft Corporation. What we will cover ... Development Tips And Tricks Cookieless sessions steps ... – PowerPoint PPT presentation

Number of Views:280
Avg rating:3.0/5.0
Slides: 63
Provided by: maine
Category:
Tags: asp | net | tips | tricks

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: ASP.NET Tips and Tricks


1
ASP.NET Tips and Tricks
Russ Fustino Microsoft Corporation
2
What we will cover
  • Development Tips and Tricks
  • Error Handling Tips and Tricks
  • Production Tips and Tricks

3
Session Prerequisites
  • ASP
  • Basic knowledge of ASP.NET

Level 300
4
Agenda
  • Development Tips and Tricks
  • Error Handling Tips and Tricks
  • Production Tips and Tricks

5
Development Tips And Tricks File upload
  • ASP.NET provides built-in file upload support
  • No posting acceptor required
  • No third party components required
  • Accessible through two APIs
  • Request.Files collection
  • server control
  • HttpPostedFile Object
  • HttpPostedFile.InputStream
  • HttpPostedFile.ContentType
  • HttpPostedFile.FileName
  • HttpPostedFile.SaveAs(fileLocation)

6
Development Tips And Tricks File upload - Notes
  • ASP.NET provides built-in file upload support
  • No posting acceptor required
  • No third party components required
  • Accessible through two APIs
  • Request.Files collection
  • server control
  • HttpPostedFile Object
  • HttpPostedFile.InputStream
  • HttpPostedFile.ContentType
  • HttpPostedFile.FileName
  • HttpPostedFile.SaveAs(fileLocation)

7
Development Tips And Tricks File upload example
  • Sub Btn_Click(Sender as Object, E as EventArgs)
  • UploadFile.PostedFile.SaveAs("c\foo.txt")
  • End Sub
  • runatserver
  • Select File To Upload
  • runatserver
  • runatserver/

8
Demonstration 1File Upload
9
Development Tips And Tricks Richer file upload
  • File system is not the only option
  • Example Storing within SQL
  • Access uploaded file as byte array
  • Store file within SQL as image (blob)
  • Store ContentType and ContentLength also
  • Provide Edit Link to display page
  • Edit Link Page sets ContentType header and then
    writes binary array back to client

10
Demonstration 2File Upload With SQL
11
Development Tips And Tricks Image generation
  • Rich server image generation
  • Additionally supports resizing cropping
  • Overlays on top of existing images
  • Read/Write Any Standard IO Stream
  • System.Drawing
  • Dynamically generate GIFs/JPGs from .aspx
  • Set ContentType appropriately
  • Optionally output cache results

12
Demonstration 3Image Generation
13
Development Tips And Tricks ASP.NET XML Server
Control
  • ASP.NET
  • Enables output of XML
  • Enables optional XSL/T transform of XML
  • Binding options
  • File system
  • Database item
  • Built-in caching
  • Ensure efficient re-use
  • Improves performance

14
Development Tips And Tricks file sample
  • DocumentSource"SalesData.xml"
  • TransformSource"SalesChart.xsl"
  • runatserver /

15
Demonstration 4Static XML
16
Development Tips And Tricks data sample
  • Sub Page_Load(Sender as Object, E as
    EventArgs)
  • Dim conn as New SqlConnection(connectionStri
    ng)
  • Dim cmd as New SqlDataAdapter(select
    from products", conn)
  • Dim dataset As New DataSet()
  • cmd.Fill (dataset, "dataset")
  • Dim XmlDoc as XmlDocument New
    XmlDataDocument(dataset)
  • MyXml1.Document XmlDoc
  • End Sub

17
Demonstration 5Dynamically Bind XML
18
Development Tips And Tricks App settings
  • Application specific settings
  • Stored in web.config files
  • Enables devs to avoid hard-coding them
  • Administrators can later change them
  • Examples
  • Database Connection String
  • MSMQ Queue Servers
  • File Locations

19
Development Tips And Tricks App settings steps
  • Create web.config file in app vroot
  • To return value
  • Configuration.AppSettings(dsn)

keydsn valuelocalhostuidsapwdD
atabasefoo/
20
Demonstration 6Application Settings
21
Development Tips And Tricks Cookieless sessions
  • Session State no longer requires client cookie
    support for SessionID
  • Can optionally track SessionID in URL
  • Requires no code changes to app
  • All relative links continue to work

22
Development Tips And Tricks Cookieless sessions
steps
  • Create web.config file in app vroot
  • Add following text




23
Development Tips And Tricks Smart navigation
  • Eliminates browser flicker/scrolling on browser
    navigation
  • Smooth client UI but with server code
  • Automatic down-level for non-IE browsers
  • No client code changes required
  • Alternatively set in web.config file

24
Agenda
  • Development Tips and Tricks
  • Error Handling Tips and Tricks
  • Production Tips and Tricks

25
Error Handling Tips And Tricks Page tracing
  • ASP.NET supports page and app tracing
  • Easy way to include debug statements
  • No more messy Response.Write() calls!
  • Great way to collect request details
  • Server control tree
  • Server variables, headers, cookies
  • Form/Querystring parameters

26
Error Handling Tips And Tricks Page tracing steps
  • Add trace directive at top of page
  • Add trace calls throughout page
  • Trace.Write(Button Clicked)
  • Trace.Warn(Value value)
  • Access page from browser

27
Demonstration 7Page Tracing
28
Error Handling Tips And Tricks Application
tracing steps
  • Create web.config file in app vroot
  • Access tracing URL within app
  • http//localhost/approot/Trace.axd




29
Demonstration 8Application Tracing
30
Error Handling Tips And Tricks Error handling
  • .NET provides unified error architecture
  • Runtime errors done using exceptions
  • Full call stack information available w/ errors
  • Can catch/handle/throw exceptions in any .NET
    Language (including VB)
  • ASP.NET also provides declarative application
    custom error handling
  • Enable programmatic logging of problems
  • Automatically redirect users to error page when
    unhandled exceptions occur

31
Error Handling Tips And Tricks Error handling -
Notes
  • .NET provides unified error architecture
  • Runtime errors done using exceptions
  • Full call stack information available w/ errors
  • Can catch/handle/throw exceptions in any .NET
    Language (including VB)
  • ASP.NET also provides declarative application
    custom error handling
  • Enable programmatic logging of problems
  • Automatically redirect users to error page when
    unhandled exceptions occur

32
Error Handling Tips And Tricks Application_Error
  • Global application event raised if unhandled
    exception occurs
  • Provides access to current Request
  • Provides access to Exception object
  • Enables developer to log/track errors
  • Cool Tip
  • Use new EventLog class to write custom events to
    log when errors occur
  • Use new SmtpMail class to send email to
    administrators

33
Demonstration 9Writing to NT Event Log
34
Error Handling Tips And Tricks Sending SMTP mail
language"VB" runatserver Sub
Application_Error(sender as Object, e as
EventArgs) Dim MyMessage as New
MailMessage MyMessage.To
someone_at_microsoft.com" MyMessage.From
"MyAppServer" MyMessage.Subject
"Unhandled Error!!!" MyMessage.BodyFormat
MailFormat.Html MyMessage.Body
"" Request.Path _ ""
Me.Error.ToString() ""
SmtpMail.Send(MyMessage) End Sub
35
Error Handling Tips And Tricks Custom errors
  • Enable easy way to hide errors from end-users
    visiting a site
  • No ugly exception error messages
  • Enables you to display a pretty site under
    repair page of your design
  • Custom Errors configured within an application
    web.config configuration file
  • Can be configured per status code number
  • Can be configured to only display remotely

36
Error Handling Tips And Tricks Custom error page
steps
  • Create web.config file in app vroot

moderemoteonly
defaultRedirecterror.htm statusCode404 redirectadminmess
age.htm/ redirectnoaccessallowed.htm/

37
Demonstration 10Custom Errors
38
Agenda
  • Development Tips and Tricks
  • Error Handling Tips and Tricks
  • Production Tips and Tricks

39
Production Tips And Tricks Performance counters
  • Per Application Performance Counters
  • Enable easily monitoring of individual ASP.NET
    applications
  • Custom Performance Counters APIs
  • Now possible to publish unique application-specifi
    c performance data
  • Great for real-time application monitoring
  • Example total orders, orders/sec

40
Demonstration 11Performance Counters
41
Production Tips And Tricks Process model recovery
  • ASP.NET runs code in an external worker process
    aspnet_wp.exe
  • Automatic Crash Recovery
  • Automatic Memory Leak Recovery
  • Automatic Deadlock Recovery
  • Can also proactively configure worker process to
    reset itself proactively
  • Timer based
  • Request based

42
Production Tips And Tricks Process model
recovery - Notes
  • ASP.NET runs code in an external worker process
    aspnet_wp.exe
  • Automatic Crash Recovery
  • Automatic Memory Leak Recovery
  • Automatic Deadlock Recovery
  • Can also proactively configure worker process to
    reset itself proactively
  • Timer based
  • Request based

43
Production Tips And Tricks Reliable session state
  • Session State can now be external from ASP.NET
    Worker Process
  • ASPState Windows NT Service
  • SQL Server
  • Big reliability wins
  • Session state survives crashes/restarts
  • Enables Web farm deployment
  • Multiple FE machines point to a common state store

44
Production Tips And Tricks External session
state steps
  • Start ASP State Service on a machine
  • net start aspnet_state
  • Create web.config file in app vroot, and point
    it at state service machine

modeStateServer
stateConnectionStringtcpipserverport /

45
Session Summary
  • Very easy to implement
  • Little or no coding required for most
  • Enhances the reliability of your apps

46
For More Information
  • MSDN Web site at
  • msdn.microsoft.com
  • ASP.NET Quickstart at
  • http//www.asp.net
  • 900 samples that can be run online
  • ASP.NET discussion lists
  • For good best practice reference applications,
    please visit IBuySpy
  • http//www.IBuySpy.com

47
MS PressEssential Resources for Developers
Find out other titles from MS Press books
at www.microsoft.com/mspress Choose from Windows
2000, SQL Server 2000, Exchange 2000, Office
2000, .NET Framework, C, VB.NET, ASP.NET, and
XML
48
TrainingTraining Resources for IT Professionals
  • Introduction to ASP.NET
  • Course 2063
  • Available Now

To locate a training provider for this course,
please access mcspreferral.microsoft.com/default.a
sp Microsoft Certified Technical Education
Centers (CTECs) are Microsofts premier partners
for training services
49
MSDNEssential Resources for Developers
Subscription Services
Library, Professional, Universal Delivered via
CD-ROM, DVD, Web
OnlineInformation
MSDN Online, MSDN Flash
Training Events
MSDN Training, Tech-Ed, PDC, Developer Days,
MSDN/Onsite Events
Print Publications
MSDN Magazine MSDN News
MembershipPrograms
MSDN User Groups
50
Where Can I Get MSDN?
  • Visit MSDN Online atmsdn.microsoft.com
  • Register for the MSDN Flash Email Newsletter at
  • msdn.microsoft.com/flash
  • Become an MSDN CD Subscriber at
    msdn.microsoft.com/subscriptions
  • MSDN online seminars
  • msdn.microsoft.com/training/seminars
  • Attend More MSDN Events

51
Become A Microsoft Certified Solution Developer
  • What Is MCSD?
  • Premium certification for professionals who
    design and develop custom business solutions
  • How Do I attain MCSD Certification?
  • It requires passing four exams to prove
    competency with Microsoft solution architecture,
    desktop applications, distributed application
    development, and development tools
  • Where Do I Get More Information?
  • For more information about certification
    requirements, exams, and training options, visit
    www.microsoft.com/mcp

52
Microsoft Developer RoadmapProducts,
Technologies, Subscriptions
Visual Studio .NET 2002
Visual Studio 6.0
VS.NET 2003
  • Base features for XML Web services mobile app
    development
  • Client, Server Services enhancements
  • Deep integration of solution orchestration
  • Continued language innovation
  • Enterprise lifecycle tools
  • Development teams
  • Design XML Web services
  • Provide architectural guidance to teams

SOAP Toolkit 2.0
  • New product line now maps to all levels of Visual
    Studio .NET

2003
2002
2001
53
MSDN For Everyone
Visual Studio .NET
Enterprise Architect
Enterprise Developer
Professional
VB, C, C Standard
54
.NET Developer SIGS (CT, MA and ME)
msdn.microsoft.com/usergroups
  • 4th Tuesday of each month (CT)
  • CT http//www.ctmsdev.net.
  • 2nd Wed of each month (MA and ME)
  • ME http//www.mainebytes.com Feb 21 ASP.NET
    Tips and Tricks
  • MA http//www.idevtech.com
  • VB.NET 1st Thursday (MA)
  • MA http//www.nevb.com
  • BACOM 2nd Monday (MA)
  • MA http//www.bacom.com
  • Share Point Server (MA) 4th Tuesday
  • MA http//www.starit.com/sughome
  • First meeting Feb 4 7pm

55
.NET Developer SIGS (NH, VT, RI)
msdn.microsoft.com/usergroups
  • .NET user groups in NH
  • http//www.nhdnug.com
  • http//www.jjssystems.net
  • .NET user group in Burlington VT
  • First meeting Feb 11 6PM ASP.NET Tips and
    tricks
  • .Net user group for RI
  • Details coming

56
Do you have a very large shop? See Russ
(rfustino_at_microsoft.com) or Bill
(wheys_at_microsoft.com)about .NET Readiness offer.
57
If youre an ISV.
  • email Joe Stagner at NEISV_at_Microsoft.com  and
    introduce yourself!

58
.NET Blitz program
  • For your development staff with a minimum size of
    10 developers in over 300 pre-approved
    companies.
  • One day onsite training (seminar format)
  • Needs analysis
  • 90 day MSDN Universal for 5 developers
  • Contact rfustino_at_microsoft.com to see if your
    company is on the list.

59
Russ Tool Shed9am-4pm
www.microsoft.com//usa/newengland/russtoolshed
Russ FustinoPrincipal Technology
SpecialistMicrosoft Corp
To be scheduled soon! Signup for the
newsletter above for details. 
60
VS.NET Launch!
  • Feb 26 Cromwell CT 105186732
  • Feb 28 Waltham MA 9am-2pm 105186533
  • Feb 28 Waltham MA 3pm-8pm 105186549
  • Mar 5 Providence 105186566
  • Mar 13 Portland ME 105186557
  • Mar 14 Nashua NH - 105186565

61
Live Webcast Events http//www.microsoft.com/usa/
webcasts/upcoming/
  • Architecting Web Services January 14, 2002 ,
    3pmMicrosoft Webcast Presents XML Basics
    January 16, 2002, 3pm.NET Class Libraries From A
    to Z January 22, 2002, 2pm Understanding
    Visual Inheritance Jan 23, 2002 3pmAdvanced
    Web Services Using ASP .NETJanuary 29, 2002,
    2PMWebservices 101January 30, 2002 3pmAdvanced
    XML/XSLFebruary 1, 2002 330pmHow To Build
    Mobile Solutions Using the Microsoft Mobile
    Internet Toolkit February 5, 2002 2pmCaching
    ASP.NET Application Settings February 6, 2002,
    3pmBuilding a .NET Mobile Solution February 13,
    2002 3pm

62
Live Webcast Events http//www.microsoft.com/usa/
webcasts/upcoming/
  • XML and Web Enabling Legacy Applications Using
    BizTalk Server 2000 February 19, 2002
    2pmAdvanced Webpart Development February 20,
    2002 3pmHow To Develop Asynchronous Applications
    with .NET Framework February 26, 2002
    2pmIntroducing .NET Alerts February 27, 2002
    3pmPart 1 Architecting an Application using the
    .NET Framework March 5, 2002 2pmPart 2 Building
    a .NET Application March 12, 2002 2pm
  • ASP .NET - Tips and Tricks March 19, 2002 2pm

63
Tool Shed Code and PowerPoint slides
  • PowerPoint slides www.microsoft.com/usa/newengla
    nd/russtoolshed
  • Code http//www.franklins.net/russ

64
Carl Franklins VB.NET Master Class
  • Hands-on Expert VB.Net Training with Carl
    Franklin various cities in New England
  • Take Carl Franklin's acclaimed VB.NET Master
    Class http//www.deeptraining.com

65
(No Transcript)
66
Session Credits
  • Author Bill Wolfe
  • Producer/Editor Field Content Team
  • Reviewers
  • Field Content Council
About PowerShow.com