SlideShare a Scribd company logo
    Page and Application Exception Handling
    Programming the Web.config File Settings
    Asynchronous Web Page Programming
    Creating a Custom HTTP Handler




   Using the asp.net intrinsic Objects
   Determining the Browser Type
   Accessing Web Page Headers
There are certain Web programming tasks that are
outside the bounds of the basic page request–response
scenario.

   Catch unhandled exceptions at the page or
    application level.
   Read and modify settings in different configuration
    files.
   Enable asynchronous communication inside Web
    pages.
   Create a custom HTTP handler to respond to
    requests for nonstandard file types.
   To catch errors at the page level, you create a
    Page_Error event handler inside the code for each
    page for which you wish to catch unhandled errors.

   Access the Server.GetLastError method to retrieve the
    last error, and then call Server.ClearError to remove
    the error from the queue.

    private void Page_Error(object sender, EventArgs e)
    {
    Trace.Write("ERROR: " +
    Server.GetLastError().Message);
    Server.ClearError();
    }
   You define an application-wide handler by adding
    the Application_Error method to your application’s
    Global.asax file.
   Here you typically pass the error handling onto
    another page that might log the error and display
    troubleshooting information to the user by using the
    Server.Transfer method.

    void Application_Error(object sender, EventArgs e)
    {
    //code that runs when an unhandled error occurs
    Server.Transfer("HandleError.aspx");
    }
   There are times when you might want to
    programmatically edit configuration settings.

   ASP.NET provides the ASP.NET Configuration
    application programming interface (API) for this purpose.

   You use a System.Configuration.Configuration class to read
    the Web.config file and write any changes you might make.

   To create a Configuration object for the current
    application, you can use the static class
    WebConfigurationManager.
   With this class, you can read configuration sections by
    calling the GetSection and GetSectionGroup methods.

   For example, the following code sample displays the
    current authentication mode as defined in the
    <system.web><authentication> section, and then displays it
    in the Label1 control:

    AuthenticationSection section =(AuthenticationSection)
    WebConfigurationManager.GetSection("system.web/
    authentication");
    Label1.Text = section.Mode.ToString();
   Besides accessing the <system.web> section, you can
    access custom application settings using the
    WebConfigurationManager.AppSettings collection.

   The following code sample demonstrates how to display
    the MyAppSetting custom application setting (which you
    could add using the ASP.NET Web Site Configuration
    tool) in a Label control:

   Label1.Text =
    WebConfigurationManager.AppSettings["MyAppSetting"];
   Similarly, you can programmatically access connection
    strings using the
    WebConfigurationManager.ConnectionStrings collection:

   Label1.Text =
    WebConfigurationManager.ConnectionStrings["Northwi
    nd"].ConnectionString;
   If you want to make changes, however, you must choose
    a specific configuration location.
   To do this, create an instance of a Configuration object.

   To create an instance of the root Web.config file that applies to
    all applications, call the static
    WebConfigurationManager.OpenWebConfiguration method
    and pass a null parameter to create a Configuration object.

   Then, use the Configuration object to create objects for
    individual sections.

   Edit values in those sections and save the changes by
    calling Configuration.Save.
   Asynchronous programming is used to improve
    the efficiency of long-running Web pages.

   During busy times when multiple pages are
    requested simultaneously the thread pool
    responding to user requests makes Web pages
    more efficient.
1. Add the Async=”true” attribute to the @ Page directive.

2. Create events to start and end your asynchronous code
that implements
System.Web.IHttpAsyncHandler.BeingProcessRequest and
System.Web.IHttpAsyncHandler.EndProcessRequest

3. Call the AddOnPreRenderCompleteAsync method to declare
your event handlers
   An HTTP handler is code that executes when an
    HTTP request for a specific resource is made to the
    server.

   For example, when a user requests an .aspx page
    from IIS, the ASP.NET page handler is executed.
    When an .asmx file is accessed, the ASP.NET service
    handler is called.

   To create a custom Hypertext Transfer Protocol
    (HTTP) handler, you first create a class that
    implements the IHttpHandler interface (to create a
    synchronous handler) or the IHttpAsyncHandler (to
    create an asynchronous handler).
   Both handler interfaces require you to implement
    the IsReusable property and the ProcessRequest method.

   The IsReusable property specifies whether the
    IHttpHandlerFactory object (the object that actually
    calls the appropriate handler) can place your
    handlers in a pool and reuse them to increase
    performance or whether it must create new
    instances every time the handler is needed.

   The ProcessRequest method is responsible for
    actually processing the individual HTTP requests.

   Once it is created, you then register and configure
    your HTTP handler with IIS.
public class ImageHandler : IHttpHandler
{
public ImageHandler()
{}
public bool IsReusable
{
get { return false; }
}
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "image/jpeg";
}
}
   For performance reasons, IIS passes only requests
    for specific file types to ASP.NET.

   For example, IIS passes requests for .aspx, .axd,
    .ascx, and .asmx to the Aspnet_Isapi.dll file that
    performs the ASP.NET processing.

   For all other file types, including .htm, .jpg, and
    .gif, ASP.NET simply passes the file from the file
    system directly to the client browser.
1.Open IIS Manager.
2. Expand the nodes until you get to your site or Default Web
Site. Select the node for your application.
3. Double-click the Handler Mappings icon in the center pane
of IIS Manager.

4. In the Actions pane (right side), select Add Managed
Handler.

5. In the Add Managed Handler dialog box, set the Request
path to the file name or extension you wish to map, in this
case, .jpg. The Type name is the class name of the HTTP
handler. If your HTTP handler is inside the App_Code
directory, it will appear in the drop-down list.
   Alternatively, if you are using IIS 7, you can simply
    configure the handler for the file extension in your
    Web.config file. You do not, then, need to use IIS
    Manager.
   For each file extension or file name you want to
    register, create an <add> element in the
    <configuration><system.web><httpHandlers> section of
    your Web.config file:

    <configuration>
    <system.web>
    <httpHandlers>
    <add verb="*" path="*.jpg" type="ImageHandler"/>
    <add verb="*" path="*.gif" type="ImageHandler"/>
    </httpHandlers>
    </system.web>
    </configuration>
   You can use the objects inside of ASP.NET to gain
    access to a lot of useful information about your
    application, the server hosting the application, and
    the client requesting resources on the server.

   These objects are referred to as the ASP.NET intrinsic
    objects. They are exposed through objects like Page,
    Browser, Response, Request, Server, and Context.

   Together, these objects provide you a great deal of
    useful information like the user’s Internet Protocol
    (IP) address, the type of browser making the request,
    errors generated during a response, the title of a
    given page, and much more.
   To display different versions of Web pages for
    different browsers, you will need to write code
    that examines the HttpBrowserCapabilities object.

   This object is exposed through Request.Browser.
   Request .Browser has many members that you
    can use to examine individual browser
    capabilities.
   The header information of a rendered HTML
    page contains important information that helps
    describe the page.
   This includes the name of the style sheet, the title
    of the page, and metadata used by search
    engines.

   ASP.NET allows you to edit this information
    programmatically using the
    System.Web.UI.HtmlControls.HtmlHead control.

   This control is exposed via the Page.Header
    property.
   For example, you might use this to set the title of a page
    dynamically at run time based on the page’s content.

    Page.Header.Title = "Current time: " + DateTime.Now;

   To set style information for the page (using the
    <head><style> HTML tag), access Page.Header.StyleSheet.

    Style bodyStyle = new Style();
    bodyStyle.ForeColor = System.Drawing.Color.Blue;
    bodyStyle.BackColor = System.Drawing.Color.LightGray;
    Page.Header.StyleSheet.CreateStyleRule(bodyStyle, null, "
    body");

More Related Content

What's hot

Server Controls of ASP.Net
Server Controls of ASP.NetServer Controls of ASP.Net
Server Controls of ASP.Net
Hitesh Santani
 
Controls
ControlsControls
Controls
teach4uin
 
C sharp and asp.net interview questions
C sharp and asp.net interview questionsC sharp and asp.net interview questions
C sharp and asp.net interview questions
Akhil Mittal
 
ASP.Net Presentation Part1
ASP.Net Presentation Part1ASP.Net Presentation Part1
ASP.Net Presentation Part1Neeraj Mathur
 
Asp.net server control
Asp.net  server controlAsp.net  server control
Asp.net server control
Sireesh K
 
ASP.NET 12 - State Management
ASP.NET 12 - State ManagementASP.NET 12 - State Management
ASP.NET 12 - State Management
Randy Connolly
 
Data Access Options in SharePoint 2010
Data Access Options in SharePoint 2010Data Access Options in SharePoint 2010
Data Access Options in SharePoint 2010Rob Windsor
 
Asp.net server controls
Asp.net server controlsAsp.net server controls
Asp.net server controlsRaed Aldahdooh
 
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...SharePoint Saturday NY
 
ASP.NET 02 - How ASP.NET Works
ASP.NET 02 - How ASP.NET WorksASP.NET 02 - How ASP.NET Works
ASP.NET 02 - How ASP.NET Works
Randy Connolly
 
Csphtp1 20
Csphtp1 20Csphtp1 20
Csphtp1 20
HUST
 
Asp
AspAsp
SharePoint 2010 Client-side Object Model
SharePoint 2010 Client-side Object ModelSharePoint 2010 Client-side Object Model
SharePoint 2010 Client-side Object ModelPhil Wicklund
 
Asp PPT (.NET )
Asp PPT (.NET )Asp PPT (.NET )
Asp PPT (.NET )
Ankit Gupta
 
Advanced SharePoint Web Part Development
Advanced SharePoint Web Part DevelopmentAdvanced SharePoint Web Part Development
Advanced SharePoint Web Part Development
Rob Windsor
 
ASP.NET Page Life Cycle
ASP.NET Page Life CycleASP.NET Page Life Cycle
ASP.NET Page Life Cycle
Abhishek Sur
 
ASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin LauASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin LauSpiffy
 

What's hot (20)

Server Controls of ASP.Net
Server Controls of ASP.NetServer Controls of ASP.Net
Server Controls of ASP.Net
 
Controls
ControlsControls
Controls
 
C sharp and asp.net interview questions
C sharp and asp.net interview questionsC sharp and asp.net interview questions
C sharp and asp.net interview questions
 
ASP.Net Presentation Part1
ASP.Net Presentation Part1ASP.Net Presentation Part1
ASP.Net Presentation Part1
 
Asp.net server control
Asp.net  server controlAsp.net  server control
Asp.net server control
 
ASP.NET 12 - State Management
ASP.NET 12 - State ManagementASP.NET 12 - State Management
ASP.NET 12 - State Management
 
Asp.net.
Asp.net.Asp.net.
Asp.net.
 
Data Access Options in SharePoint 2010
Data Access Options in SharePoint 2010Data Access Options in SharePoint 2010
Data Access Options in SharePoint 2010
 
Asp.net server controls
Asp.net server controlsAsp.net server controls
Asp.net server controls
 
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
 
ASP.NET 02 - How ASP.NET Works
ASP.NET 02 - How ASP.NET WorksASP.NET 02 - How ASP.NET Works
ASP.NET 02 - How ASP.NET Works
 
Csphtp1 20
Csphtp1 20Csphtp1 20
Csphtp1 20
 
Asp
AspAsp
Asp
 
Asp objects
Asp objectsAsp objects
Asp objects
 
Asp
AspAsp
Asp
 
SharePoint 2010 Client-side Object Model
SharePoint 2010 Client-side Object ModelSharePoint 2010 Client-side Object Model
SharePoint 2010 Client-side Object Model
 
Asp PPT (.NET )
Asp PPT (.NET )Asp PPT (.NET )
Asp PPT (.NET )
 
Advanced SharePoint Web Part Development
Advanced SharePoint Web Part DevelopmentAdvanced SharePoint Web Part Development
Advanced SharePoint Web Part Development
 
ASP.NET Page Life Cycle
ASP.NET Page Life CycleASP.NET Page Life Cycle
ASP.NET Page Life Cycle
 
ASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin LauASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin Lau
 

Viewers also liked

Deploying configuring caching
Deploying configuring cachingDeploying configuring caching
Deploying configuring cachingaspnet123
 
Mobile application
Mobile applicationMobile application
Mobile applicationaspnet123
 
User controls
User controlsUser controls
User controlsaspnet123
 
Introducing asp
Introducing aspIntroducing asp
Introducing aspaspnet123
 
Globalization and accessibility
Globalization and accessibilityGlobalization and accessibility
Globalization and accessibilityaspnet123
 
Custom controls
Custom controlsCustom controls
Custom controlsaspnet123
 
Monitoring, troubleshooting,
Monitoring, troubleshooting,Monitoring, troubleshooting,
Monitoring, troubleshooting,aspnet123
 
ความรู้เกี่ยวกับอินเทอร์เน็ตบี
ความรู้เกี่ยวกับอินเทอร์เน็ตบีความรู้เกี่ยวกับอินเทอร์เน็ตบี
ความรู้เกี่ยวกับอินเทอร์เน็ตบีPheeranan Thetkham
 

Viewers also liked (9)

Deploying configuring caching
Deploying configuring cachingDeploying configuring caching
Deploying configuring caching
 
Mobile application
Mobile applicationMobile application
Mobile application
 
Profile
ProfileProfile
Profile
 
User controls
User controlsUser controls
User controls
 
Introducing asp
Introducing aspIntroducing asp
Introducing asp
 
Globalization and accessibility
Globalization and accessibilityGlobalization and accessibility
Globalization and accessibility
 
Custom controls
Custom controlsCustom controls
Custom controls
 
Monitoring, troubleshooting,
Monitoring, troubleshooting,Monitoring, troubleshooting,
Monitoring, troubleshooting,
 
ความรู้เกี่ยวกับอินเทอร์เน็ตบี
ความรู้เกี่ยวกับอินเทอร์เน็ตบีความรู้เกี่ยวกับอินเทอร์เน็ตบี
ความรู้เกี่ยวกับอินเทอร์เน็ตบี
 

Similar to Programming web application

11 asp.net session16
11 asp.net session1611 asp.net session16
11 asp.net session16
Vivek chan
 
13 asp.net session19
13 asp.net session1913 asp.net session19
13 asp.net session19
Vivek chan
 
A View about ASP .NET and their objectives
A View about ASP .NET and their objectivesA View about ASP .NET and their objectives
Active server pages
Active server pagesActive server pages
Active server pages
mcatahir947
 
Overview of ASP.Net by software outsourcing company india
Overview of ASP.Net by software outsourcing company indiaOverview of ASP.Net by software outsourcing company india
Overview of ASP.Net by software outsourcing company india
Jignesh Aakoliya
 
.Net course-in-mumbai-ppt
.Net course-in-mumbai-ppt.Net course-in-mumbai-ppt
.Net course-in-mumbai-ppt
vibrantuser
 
Asp.net By Durgesh Singh
Asp.net By Durgesh SinghAsp.net By Durgesh Singh
Asp.net By Durgesh Singh
imdurgesh
 
Ajax
AjaxAjax
Active Server Page - ( ASP )
Active Server Page - ( ASP )Active Server Page - ( ASP )
Active Server Page - ( ASP )
MohitJoshi154
 
Asp.Net Ajax Component Development
Asp.Net Ajax Component DevelopmentAsp.Net Ajax Component Development
Asp.Net Ajax Component DevelopmentChui-Wen Chiu
 
05 asp.net session07
05 asp.net session0705 asp.net session07
05 asp.net session07
Vivek chan
 
Asp.net architecture
Asp.net architectureAsp.net architecture
Asp.net architectureIblesoft
 
Creating web form
Creating web formCreating web form
Creating web form
mentorrbuddy
 
Creating web form
Creating web formCreating web form
Creating web form
mentorrbuddy
 
The complete ASP.NET (IIS) Tutorial with code example in power point slide show
The complete ASP.NET (IIS) Tutorial with code example in power point slide showThe complete ASP.NET (IIS) Tutorial with code example in power point slide show
The complete ASP.NET (IIS) Tutorial with code example in power point slide show
Subhas Malik
 
SharePoint 2007 Presentation
SharePoint 2007 PresentationSharePoint 2007 Presentation
SharePoint 2007 PresentationAjay Jain
 
Asp .net web form fundamentals
Asp .net web form fundamentalsAsp .net web form fundamentals
Asp .net web form fundamentalsGopal Ji Singh
 
Top 15-asp-dot-net-interview-questions-and-answers
Top 15-asp-dot-net-interview-questions-and-answersTop 15-asp-dot-net-interview-questions-and-answers
Top 15-asp-dot-net-interview-questions-and-answers
sonia merchant
 

Similar to Programming web application (20)

ASP.NET - Web Programming
ASP.NET - Web ProgrammingASP.NET - Web Programming
ASP.NET - Web Programming
 
11 asp.net session16
11 asp.net session1611 asp.net session16
11 asp.net session16
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
13 asp.net session19
13 asp.net session1913 asp.net session19
13 asp.net session19
 
A View about ASP .NET and their objectives
A View about ASP .NET and their objectivesA View about ASP .NET and their objectives
A View about ASP .NET and their objectives
 
Active server pages
Active server pagesActive server pages
Active server pages
 
Overview of ASP.Net by software outsourcing company india
Overview of ASP.Net by software outsourcing company indiaOverview of ASP.Net by software outsourcing company india
Overview of ASP.Net by software outsourcing company india
 
.Net course-in-mumbai-ppt
.Net course-in-mumbai-ppt.Net course-in-mumbai-ppt
.Net course-in-mumbai-ppt
 
Asp.net By Durgesh Singh
Asp.net By Durgesh SinghAsp.net By Durgesh Singh
Asp.net By Durgesh Singh
 
Ajax
AjaxAjax
Ajax
 
Active Server Page - ( ASP )
Active Server Page - ( ASP )Active Server Page - ( ASP )
Active Server Page - ( ASP )
 
Asp.Net Ajax Component Development
Asp.Net Ajax Component DevelopmentAsp.Net Ajax Component Development
Asp.Net Ajax Component Development
 
05 asp.net session07
05 asp.net session0705 asp.net session07
05 asp.net session07
 
Asp.net architecture
Asp.net architectureAsp.net architecture
Asp.net architecture
 
Creating web form
Creating web formCreating web form
Creating web form
 
Creating web form
Creating web formCreating web form
Creating web form
 
The complete ASP.NET (IIS) Tutorial with code example in power point slide show
The complete ASP.NET (IIS) Tutorial with code example in power point slide showThe complete ASP.NET (IIS) Tutorial with code example in power point slide show
The complete ASP.NET (IIS) Tutorial with code example in power point slide show
 
SharePoint 2007 Presentation
SharePoint 2007 PresentationSharePoint 2007 Presentation
SharePoint 2007 Presentation
 
Asp .net web form fundamentals
Asp .net web form fundamentalsAsp .net web form fundamentals
Asp .net web form fundamentals
 
Top 15-asp-dot-net-interview-questions-and-answers
Top 15-asp-dot-net-interview-questions-and-answersTop 15-asp-dot-net-interview-questions-and-answers
Top 15-asp-dot-net-interview-questions-and-answers
 

Recently uploaded

FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 

Programming web application

  • 1.
  • 2. Page and Application Exception Handling  Programming the Web.config File Settings  Asynchronous Web Page Programming  Creating a Custom HTTP Handler  Using the asp.net intrinsic Objects  Determining the Browser Type  Accessing Web Page Headers
  • 3. There are certain Web programming tasks that are outside the bounds of the basic page request–response scenario.  Catch unhandled exceptions at the page or application level.  Read and modify settings in different configuration files.  Enable asynchronous communication inside Web pages.  Create a custom HTTP handler to respond to requests for nonstandard file types.
  • 4. To catch errors at the page level, you create a Page_Error event handler inside the code for each page for which you wish to catch unhandled errors.  Access the Server.GetLastError method to retrieve the last error, and then call Server.ClearError to remove the error from the queue. private void Page_Error(object sender, EventArgs e) { Trace.Write("ERROR: " + Server.GetLastError().Message); Server.ClearError(); }
  • 5. You define an application-wide handler by adding the Application_Error method to your application’s Global.asax file.  Here you typically pass the error handling onto another page that might log the error and display troubleshooting information to the user by using the Server.Transfer method. void Application_Error(object sender, EventArgs e) { //code that runs when an unhandled error occurs Server.Transfer("HandleError.aspx"); }
  • 6. There are times when you might want to programmatically edit configuration settings.  ASP.NET provides the ASP.NET Configuration application programming interface (API) for this purpose.  You use a System.Configuration.Configuration class to read the Web.config file and write any changes you might make.  To create a Configuration object for the current application, you can use the static class WebConfigurationManager.
  • 7. With this class, you can read configuration sections by calling the GetSection and GetSectionGroup methods.  For example, the following code sample displays the current authentication mode as defined in the <system.web><authentication> section, and then displays it in the Label1 control: AuthenticationSection section =(AuthenticationSection) WebConfigurationManager.GetSection("system.web/ authentication"); Label1.Text = section.Mode.ToString();
  • 8. Besides accessing the <system.web> section, you can access custom application settings using the WebConfigurationManager.AppSettings collection.  The following code sample demonstrates how to display the MyAppSetting custom application setting (which you could add using the ASP.NET Web Site Configuration tool) in a Label control:  Label1.Text = WebConfigurationManager.AppSettings["MyAppSetting"];
  • 9. Similarly, you can programmatically access connection strings using the WebConfigurationManager.ConnectionStrings collection:  Label1.Text = WebConfigurationManager.ConnectionStrings["Northwi nd"].ConnectionString;
  • 10. If you want to make changes, however, you must choose a specific configuration location.  To do this, create an instance of a Configuration object.  To create an instance of the root Web.config file that applies to all applications, call the static WebConfigurationManager.OpenWebConfiguration method and pass a null parameter to create a Configuration object.  Then, use the Configuration object to create objects for individual sections.  Edit values in those sections and save the changes by calling Configuration.Save.
  • 11. Asynchronous programming is used to improve the efficiency of long-running Web pages.  During busy times when multiple pages are requested simultaneously the thread pool responding to user requests makes Web pages more efficient.
  • 12. 1. Add the Async=”true” attribute to the @ Page directive. 2. Create events to start and end your asynchronous code that implements System.Web.IHttpAsyncHandler.BeingProcessRequest and System.Web.IHttpAsyncHandler.EndProcessRequest 3. Call the AddOnPreRenderCompleteAsync method to declare your event handlers
  • 13. An HTTP handler is code that executes when an HTTP request for a specific resource is made to the server.  For example, when a user requests an .aspx page from IIS, the ASP.NET page handler is executed. When an .asmx file is accessed, the ASP.NET service handler is called.  To create a custom Hypertext Transfer Protocol (HTTP) handler, you first create a class that implements the IHttpHandler interface (to create a synchronous handler) or the IHttpAsyncHandler (to create an asynchronous handler).
  • 14. Both handler interfaces require you to implement the IsReusable property and the ProcessRequest method.  The IsReusable property specifies whether the IHttpHandlerFactory object (the object that actually calls the appropriate handler) can place your handlers in a pool and reuse them to increase performance or whether it must create new instances every time the handler is needed.  The ProcessRequest method is responsible for actually processing the individual HTTP requests.  Once it is created, you then register and configure your HTTP handler with IIS.
  • 15. public class ImageHandler : IHttpHandler { public ImageHandler() {} public bool IsReusable { get { return false; } } public void ProcessRequest(HttpContext context) { context.Response.ContentType = "image/jpeg"; } }
  • 16. For performance reasons, IIS passes only requests for specific file types to ASP.NET.  For example, IIS passes requests for .aspx, .axd, .ascx, and .asmx to the Aspnet_Isapi.dll file that performs the ASP.NET processing.  For all other file types, including .htm, .jpg, and .gif, ASP.NET simply passes the file from the file system directly to the client browser.
  • 17. 1.Open IIS Manager. 2. Expand the nodes until you get to your site or Default Web Site. Select the node for your application. 3. Double-click the Handler Mappings icon in the center pane of IIS Manager. 4. In the Actions pane (right side), select Add Managed Handler. 5. In the Add Managed Handler dialog box, set the Request path to the file name or extension you wish to map, in this case, .jpg. The Type name is the class name of the HTTP handler. If your HTTP handler is inside the App_Code directory, it will appear in the drop-down list.
  • 18. Alternatively, if you are using IIS 7, you can simply configure the handler for the file extension in your Web.config file. You do not, then, need to use IIS Manager.  For each file extension or file name you want to register, create an <add> element in the <configuration><system.web><httpHandlers> section of your Web.config file: <configuration> <system.web> <httpHandlers> <add verb="*" path="*.jpg" type="ImageHandler"/> <add verb="*" path="*.gif" type="ImageHandler"/> </httpHandlers> </system.web> </configuration>
  • 19. You can use the objects inside of ASP.NET to gain access to a lot of useful information about your application, the server hosting the application, and the client requesting resources on the server.  These objects are referred to as the ASP.NET intrinsic objects. They are exposed through objects like Page, Browser, Response, Request, Server, and Context.  Together, these objects provide you a great deal of useful information like the user’s Internet Protocol (IP) address, the type of browser making the request, errors generated during a response, the title of a given page, and much more.
  • 20.
  • 21. To display different versions of Web pages for different browsers, you will need to write code that examines the HttpBrowserCapabilities object.  This object is exposed through Request.Browser.  Request .Browser has many members that you can use to examine individual browser capabilities.
  • 22.
  • 23. The header information of a rendered HTML page contains important information that helps describe the page.  This includes the name of the style sheet, the title of the page, and metadata used by search engines.  ASP.NET allows you to edit this information programmatically using the System.Web.UI.HtmlControls.HtmlHead control.  This control is exposed via the Page.Header property.
  • 24. For example, you might use this to set the title of a page dynamically at run time based on the page’s content. Page.Header.Title = "Current time: " + DateTime.Now;  To set style information for the page (using the <head><style> HTML tag), access Page.Header.StyleSheet. Style bodyStyle = new Style(); bodyStyle.ForeColor = System.Drawing.Color.Blue; bodyStyle.BackColor = System.Drawing.Color.LightGray; Page.Header.StyleSheet.CreateStyleRule(bodyStyle, null, " body");