Synapseindia DOTNET Development Part 1

Embed Size (px)

Citation preview

  • 8/10/2019 Synapseindia DOTNET Development Part 1

    1/18

    ASP.NET Tips and Tricks

  • 8/10/2019 Synapseindia DOTNET Development Part 1

    2/18

    What we will cover

    Development Tips and Tricks

    Error HandlingTips and Tricks

    Production Tips and Tricks

  • 8/10/2019 Synapseindia DOTNET Development Part 1

    3/18

    Session Prerequisites

    ASP Basic knowledge of ASP.NET

  • 8/10/2019 Synapseindia DOTNET Development Part 1

    4/18

    Agenda

    Development Tips and Tricks

    Error Handling Tips and Tricks

    Production Tips and Tricks

  • 8/10/2019 Synapseindia DOTNET Development Part 1

    5/18

    Development Tips And Tricks

    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

    HttpPostedFileObject:

    HttpPostedFile.InputStream HttpPostedFile.ContentType

    HttpPostedFile.FileName

    HttpPostedFile.SaveAs(fileLocation)

  • 8/10/2019 Synapseindia DOTNET Development Part 1

    6/18

    Sub Btn_Click(Sender as Object, E as EventArgs)

    UploadFile.PostedFile.SaveAs("c:\foo.txt")

    End Sub

    Select File To Upload:

  • 8/10/2019 Synapseindia DOTNET Development Part 1

    7/18

    Demonstration 1File Upload

  • 8/10/2019 Synapseindia DOTNET Development Part 1

    8/18

    File system is not the only option

    Example: Storing within SQL

    Access uploaded file as bytearray

    Store file within SQL as image (blob)

    Store ContentTypeand ContentLengthalso

    Provide Edit Link to display page

    Edit Link Page sets ContentTypeheader and thenwrites binary array back to client

    Development Tips And Tricks

  • 8/10/2019 Synapseindia DOTNET Development Part 1

    9/18

    Demonstration 2File Upload With SQL

  • 8/10/2019 Synapseindia DOTNET Development Part 1

    10/18

    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 ContentTypeappropriately

    Optionally output cache results

    Development Tips And Tricks

  • 8/10/2019 Synapseindia DOTNET Development Part 1

    11/18

    Demonstration 3Image Generation

  • 8/10/2019 Synapseindia DOTNET Development Part 1

    12/18

    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

    Development Tips And TricksASP.NET XML Server Control

  • 8/10/2019 Synapseindia DOTNET Development Part 1

    13/18

    Development Tips And Tricks

    file sample

  • 8/10/2019 Synapseindia DOTNET Development Part 1

    14/18

    Demonstration 4Static XML

  • 8/10/2019 Synapseindia DOTNET Development Part 1

    15/18

    Sub Page_Load(Sender as Object, E as EventArgs)Dim conn as New SqlConnection(connectionString)

    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

    Development Tips And Tricks

    data sample

  • 8/10/2019 Synapseindia DOTNET Development Part 1

    16/18

    Demonstration 5Dynamically Bind XML

  • 8/10/2019 Synapseindia DOTNET Development Part 1

    17/18

    Application specific settings

    Stored in web.configfiles

    Enables devs to avoid hard-coding them

    Administrators can later change them

    Examples:

    Database Connection String MSMQ Queue Servers

    File Locations

    Development Tips And TricksApp settings

  • 8/10/2019 Synapseindia DOTNET Development Part 1

    18/18

    1. Create web.config file in app vroot:

    To return value:

    Configuration.AppSettings(dsn)

    Development Tips And TricksApp settings steps