Pages

Ads 468x60px

Labels

Tuesday, February 26, 2013

Custom Controls





Introduction

Will need to create user control really just pages embedded within other pages that you can use that technology to create controls like the other controls that are built into the.net framework if you want to create controls the look and feel like the built in one's got right some code does the way around it will take a little more effort but you'll see that the benefits outweigh the effort because you'll have complete control over what you're controlling this in the output page in this section will look at starting with the basic template that Microsoft provides for creating a custom control and then we'll revisit the state list user control and we write it as a custom control to see how much effort is involved will finish by adding some ease-of-use features such as providing a default property a default events for the custom control.



Custom Controls   1

In order to create the new custom control all create a new project this project will be a web project@ASP.net server control all except the default name and location that's fine with me and yes I will not save my changes to that project in the new custom control project there's a class name server control 1.VB first of all note that this thing inherits from the web control class the web control class provide some built-in functionality for creating custom controls here we have a number of attributes that define the behavior of this property but we also have make it clear it user rated we have a text property this control.

 This sample template if we disregard these attributes for now of these attributes will come back and look at those later the text property is pretty simple it has a string tests it gets its value from of view state variable name text this verbal stored in view state so it will survive a round-trip to the server along with this page if S is nothing then we return the name of this control less of the idea of the controls in square brackets otherwise return the text which came from the view state property that's the property getter the property setter this takes the value we want to supply the text property and puts it into the view state variable name text.

 So that's the code that handles getting and setting the text property of this control that's really the only property has there's also down here and override for the render contents method of the web control base class the render contents method gets called with ASP.net needs to draw the contents of the control onto the output page and what is this control do when asked to render its contents does nothing more than take its text property and white it into the output stream the HTML text writer represents the stream into which were writing the HTML output the additional text writer has a couple of tricks up its sleeve that make it easy.





Wednesday, February 20, 2013

User Control 6





 Which if you remember call to find index method figures out which index to go to and sets the drop-down list to show that value will that's all the code there is to make of this state drop-down list control work was review how it works also led to stay here and when I do the selected index changed event of the internal drop-down list raises which causes the user control to raise the selected index changed event which causes this page to refresh itself and placed into this text box the selected value if I type a value here and click set value it sets the value property of the user control to match the value of the text in the text box





Summary
It is unfortunate that the two names for the two types of the controls you can create yourself or so confusing what the user control what's a custom control really a user control is like a little page to drop on to another page so-called page letter something but it's completely unambiguous a user control is a control you create by dropping other controls on wood design surface and vendors adding code custom controls.
 Control you create from scratch is the topic for different section but in terms of user controls To stop here the user before we just created seems to have a lot of capabilities it easy to create user controls but what if you want to package and create controls like the normal server controls what you want to add your controls to the toolbox on the design surface what if you want to use the same control across multiple application domains in multiple applications for that you need custom controls and that's the topic of our next section

Sunday, February 17, 2013

User Control 5




 More thought event handler is a little higher up here we are and it's the selected index changed event would like to expose or raise from this user control what I need to do is declare a public event selected index changed I can call it whatever I want but it certainly is more polite to name it something that's familiar to the user or the consumer of this control and that would be selected index changed every defined event in.net has a well-known or fixed signature in this case.
This event handler needs to receive sender as object and be as event darks five declared my event that way I declare the event that I'm going to raise and here in the selected index changed event of my private drop-down list that is inside the control all of you to do is raise the event back out to whoever's listening that is whoever has consumed this control this is how you raise an event from within a user control you receive the event you care about in this case the selected index changed event of the drop-down list of inside the user control and then.

 You raise an event which corresponds to what you want the consumer of your control to see otherwise they can't receive any events of the drop-down list that's embedded inside your user control this isn't a good example of this because our user control contains only a single wheel control if there were multiple controls this would be more obvious because of their multiple controls how would the user control know how to map internal events to external events and so were required to raise this event to the outside world and I'm raising the selected index change that I just defined here passing me that is the user control and be whatever got passed to me here and those are passed out to the consumer of this control.

 Well that's all the code there is so let's look at the completed page to see how it handles the events of this user control here's the user control and you can see that I will see the events here at all on the properties window but if I go into the code window I should be able to go to state list one and five it selected index changed event all these other events listed here those are events that are exposed by the user control container notice there are no other events of a drop-down list exposed here because I did expose and all these other events, for every user control they all get them for free my selected index changed event I've handled by taking the value of the state list and placing it into the text of the text box of course I also have code that takes the text of the text box and shoves it into the value of the state list when I do that I sent the value is the list.


Friday, February 15, 2013

User Control 4




 It once again and looked to see what's actually rendered in this page the page needs to include a select control with a lot of options and so we need our drop-down list to have these options with the text is the long name and the value is the short name will see about to happen here's our control look at the markup is nothing more than well a control with ASP drop-down list on the ASC X page okay.

 Was look at the code for this thing it's all done in the code in the markup that's all there was a drop-down list and the story here in the class we have an array of well at to Colin array of values short name, long name there a lot of other data structures like reviews don't yell at me it was the simplest using an array and that's why went with I like the array because it's easy to initialize at design time so here is the contents of the array and in the page load event handler we fill the list the load list procedure we go there simply clears out the state drop-down list and loops through every item in the states array and for each one adds a new item to the drop-down list by creating a new list item and retrieving the short name.

 Actually is the long name and the short name because of the list item when you create one you generate the text to be displayed first and the value second this is the text to be displayed this is the value other also control properties I did auto post back text and value was look at those here I have auto post back text and value what is auto post back work with it gets the auto post back property of the drop-down list and it sets the auto post back property of the drop-down list can be easier met the value property gets the value of the selected item of the drop-down list and sets the selected index to be the index corresponding to the value supply remember if I type TX and push it into the value of this drop-down list I need to figure out which index that is defined index procedure was a somewhat brute force the five index procedure just scans the list to find a match once.

 It finds a match he returns the index believe me there are better ways to do this I didn't want to dig into here esoteric means of searching data structures like It as simple as possible so back up here I'll find it there we go the value when you want to set we find the index and stick that in the selected index property of the drop-down list finally there's a read only text property that retrieves the text of the list and that returns the text of the selected item in the drop-down list to the properties really aren't very complicated handling the event requires a little.

Wednesday, February 13, 2013

User Control 3






 That is CX here's stateless.ASC X and here is footer.ASC X would define the layout of this page in a way that we can reuse on multiple pages within the site and we started using a user control now going to look at a more complex user control this user control provides a list of states and how often have you built a page.

 Where you need to provide a list of states for your country I'll be using the United States but I'm sure every developer has done this for his or her own locale this control needs to allow you to support auto post back so that choosing estate will trigger some event automatically it needs to provide text and value properties you can look at one view of the state name and perhaps return a different one either show you the short name and return the long name or show you the long name and return the short name.

 It needs to raise the selected index changed event you can react to the event were the user selects a state offices been done for you were going to look at state list.ASC X in the sample project another data has to come from somewhere and we could use XML file or database but a static data we haven't added ministate store list of states a long time so this is hardcoded is actually provided in the control itself the user control needs to provide some properties for example.

 It needs an auto post back Boolean property it needs a text property and it needs of value property will investigate each of these in the code for the control finally the control needs to raise events will declare the event and then raise it when necessary let's step back and look at the state list user control over the completed.aspx page into the browser so we can investigate the behavior of the drop-down list here's our state drop-down list and it displays a list of the United States the long names if I choose one it's short name appears in this text box there must be some event that occurs my select one and we retrieve.

The value of the drop-down list and place the value in this text box there is also the ability to set the value suffice set this to a state and click set value it sets the value of this list so you can see we can retrieve the value when the user makes a selection and set the value based on some external event while that's pretty much all this thing does not too exciting but it does satisfy a need that is it encapsulates some commonly used functionality lets look at the source code to see how it works here we have state list.ASC X and all view the designer first well it's a drop-down list that spirit not much here but what needs to be the output of this drop-down list and it shows before was run.

Monday, February 11, 2013

User Control 2









So now how do we use this thing already how the page onto which I'd like to place this order hitter the before footer page consists basically of some header information some content and now to use footer I just take it and drag it onto the page went there we go cut with above the right place I wanted to was drug or I do want it which must be down here there we go so we now have the footer dragged onto the page will use it done note that if you're coming from a previous version of Visual Studio you might notice something different user controls in early versions of Visual Studio.
 Just displayed a great blog on the page we drop them off in this version we actually see a design time experience which contains the content of the user control the user control has a task pane which includes two items edit user control and refresh context refers content is useful if you modify the user control somewhere else and edit user control takes you two as you might imagine the designer for the user control itself because on this page I Really modified the user control have to go to its designer when you track the user control onto the page Visual Studio adds that only a reference to the user control.
 Itself but up here a register directive the register directive indicates they were using a user control from some other source and the source areas footer.ASC X there's a tag name we used to refer to this user control and attack prefix every control in ASP.net page that is part of ASP.net and not HTML include some sort of tag prefix like ASP will this user control as a tag prefix of you see one hears the controls tag footer at ID for it every control has to have an idea of play along with ASP.net.
 And is set to run@theserverlikeeveryotherASP.net control so it looks like a normal control it feels like a normal control yet you decided using the ASC X designer here is to prove a point I've gone a little farther on that before footer page there were some header information I might like that on every page as well so I've created a header.ASC X which includes a table and the image of that cute little puppy and the header information and there is my header.ASC X ready to be dropped on a page.
 And I have a page right dropped off completed.ASC X includes header.ASC X and footer is CX and one more user control that will be discussing in the next chunk you can see down here we have our user controls use the header here's the footer and here's the state list will be talking about soon the only constant is defined here is a text box and a button and if we look at the design for the page here's the text box here's the button here's header.

User Controls






Introduction
Him will you have a website which you need to repeatedly use a group of controls that record layout that group of controls on these pages may be copying and pasting from one page to the other that work for one of that group of controls had some code it needed to run in reaction to some user of it in that case what you really need is some way to create your own single control that contains all those controls that.
 You could then drop onto a webpage and have it run some code like a normal control what you can do that you can create a user control that is basically a conglomeration of other controls in addition you can also create a custom control which is a control like those you find a little box in this section will investigate user controls in the next section will investigate creating custom controls.


User Control      1

First are user controls these are really like a little page that you embed within other pages these must have a.ASC X extension and you design them as if they were a normal page you can add code to react to events and then you can treat them as a reusable entity there really are intended for use within a single site however that you can create a custom control a custom control is created from scratch these acts and feel like built-in server controls because they are the same thing as built-in server controls all.
 The server controls that are built in to the toolbox are actually Microsoft provided custom controls these each inherit from a base class and that added members as necessary the result is an assembly which contains the control of a custom controls only job really is to render output just like a standard built-in control its job is to spit out HTML when the page is rendered in this section will begin by looking at creating a simple user control imagine that you want some standard user interface design.
 And you liked implemented across all the pages in your website perhaps your standard menu or footer or hitter on every page you could of course critical master page but that's not the point here let's take a look of example I've already created where I have thought of information in a user control how does get there by right clicked on my project chose add new item and then shows Web user control I'm a bit footer is CX 40 Dundas was canceled for now here is forgot is the X if I look at this markup you'll see that it looks like a page really is very much like a page except that has a control directive instead of a page directive all we have on your right now is a style sheet link and then a horizontal rule and some text for looking design it's not totally overwhelming it's just text okay.



Saturday, February 9, 2013

Health Monitoring : 3







 I need to do is configure web.config open up the web.config file here and I'll go over to the web health monitoring.config this configuration information this health monitoring element of the web.config file let you specify the SQL Web event provider class you can configure this provider and specify the events that you want to monitor in the rules section 2 in this case which is defined in application lifetime events roll specifying all events as well as the provider that is created appear as little bit more to talk about for configuring and using health monitoring the health monitoring section that we just let that contains only two of the elements required for configuration the providers that were going to use in this case a SQL Server and the rules that we want to use there's.

 A third required element called event mappings and this is inherited from the root web.config file the event name value all events that we sign the web.config file refers to one of the event mappings in the root web.config file slots and look at that section or have opened the root web.config file and I scroll down to the health monitoring section. We'll see the built-in event mappings which are named categories of event data based on the event type in a range of that codes the providers listed here are the three built-in providers for sending event data to the Windows event log or to Debbie on my Windows management instrumentation the role specify provider and event mapping and configuration options that you can use to throttle the flow of data and you can use profiles to centralize the configuration of those throttling options by specifying sets of providers rules and event mappings you determine which event data is recorded and where it is recorded.

So scroll down a bit so we have profiles rules and then we have various event mappings settle to find within the root web.config file which means available to all ASP.net applications so sickle look at the view offense page I'll govern the design view and you can see that we just have a simple grid with the SQL data source the SQL data source is configured to read from the ASP net Web event events so can take a look at the source for that and you can see the select statement that is going to be executed in order to read that data and open everything in order by the event in descending order we also delete command defined so that you can delete all existing events in order to clear out the database will use the code behind the page and all we have is within the page unload event is going to clean up all the old events that are contained within the database and to do that all we need to do is call the delete method of the web events data source) run the application and you can see the most recent event data recorded within the database when you close the page then it deletes all of the old events


Summary

If you have a website that has to be highly reliable and scalable monitoring itself with weather events is just what the doctor ordered with performance data in a SQL Server database you can analyze it to your heart's content to find and fix problems before anyone else notices the such as a user who find your site down with the.net is monitoring stuff shouldn't you be to


Health Monitoring : 2




So we dim up a trace context record object which we could do within the forage as well and then look through the collection of trace records and output information about each basically just outputting that category and the message so that had run this application you can see that you get information about all of the events that fired as part of this page as well as the custom trace message that we output from the pages load event procedure instead of displaying the output on the page could also directed to an external source such as a database and in this.

 Way you can create the equivalent of your own trace listener without using system.diagnostics one of the channel providers that you can use to monitor application health saves data to a SQL Server database is a great option because he can send a lot of information and it makes it easily available and has a lot of failover features as well the first step in setting up monitoring is to create the application services database for SQL Server for some services it makes sense to place this data in the app data folder in your application directory that uses SQL express but for event data you probably want to use a single central database as a mentor to look at doing in this example can be pretty tedious to set up a database by yourself.

Say ASP.net provides an ASP.net _ red SQL utility this is part of the.net framework you can use this to create the SQL Server database or to configure options for an existing one and you can find this utility in the Windows/Microsoft.net/framework version number folder on your computer as a couple different ways to run this utility you can run from the command line or you can run it as a Windows wizard application was sickle look at running the wizard the easiest way to run the utility is by using the Visual Studio command prompt this is nice because in early has all the path set up to the various utilities used by the.net framework and Visual Studio rights of the wizard is running out click on the next button and it prompts me for what I wanted to go to configure SQL Server for application services.

But I can also remove the services if I want to take them away from his computer click on next and in this case I'm going to use the SQL express instance on this machine all connected using Windows authentication and only if the default database selection because I will create a new database on click on next and gives me a summary of what is going to do and I'll click on next and I'll take care of configuring the database I think evidence the database is been created or modified right all click out of the wizard and shut down the command prompt and were all set to start saving health information to that database the one other thing.


Health Monitoring




Introduction

ASP.net web events provide a framework that you can plug into in order to monitor your applications help this is another example where ASP.net uses a feature internally and exposes the infrastructure to developers you can use when advanced report on the health of a website and audit you can even develop and race custom events to monitor the things that are important to administrators determine which events.

 They are interested in by using event subscriptions that are controlled by configuration files which can also specify channels through which the events are delivered out of the box channel providers handle saving events to SQL Server sending event reports through email writing events to the event log and forwarding events through Windows management instrumentation.



Health Monitoring   : 1

You had to accept the default rendering and it wasn't easy to redirect output to a persistent store but now ASP.net provides programmatic access to trace output through the system.Web.trace context object using the trace finished event you can hook into trace finished and do whatever you want with the output the trace finished event exposes trace messages as a collection of trace context record objects after all the request information is been gathered by registering a trace context event handler delegate you can iterate through the trace messages.

And write them to response stream a trace context record object encapsulates the trace message category any associated exception and whether the trace record was written by the trace context.warn method in a several properties he can take advantage of the category property gets the user-defined type category for the trace record so like other trace information you can categorize the information that your gathering error info gets an exception if one is associated with the trace record is warning its a value indicating whether the trace record is associated with the trace context.warn method call and finally the message property gets the user-defined.

Trace message that's associated with the object classical look at how you can take advantage of the trace context record object this example shows how to register a trace context event handler to handle the trace finished event this is the code behind the trace context.aspx page in the page load event procedure we have to add a handler for the traced finished event and so forth that we just pass in the address of the on traced finish method and then we go ahead and write some custom information the first thing that the page load event procedure does is it adds a handler to the trace finished .

Event and we pass in the address of the entrees finished method and write out a message to the trace object appears that entrees finished method like pretty much all events within the.net framework he gets a couple of parameters against the Senators object to identify what caused this event or more portly for a purpose here we get this trace context event arcs parameter and this contains a collection of trace records.


Thursday, February 7, 2013

Listeners : 8





So in this example the config file the controls compilation of the component is in the web.config and the important setting here is I have a compiler options attribute that specifies that I want to output trace messages to have compiler options here for both C sharp in VB because you can have code of both types within that Apco directory so by including both have the flexibility of including trace information for any kind of code that I put within that Apco directory that location is special within ASP.net.

Applications right with that the application all set up so go ahead and run until select defaults and executed and I'll click on the webpage trace listener back over to Visual Studio as you can see the trace output is in the output window and I have the system.diagnostics.trace messages included in integrated together with the ASP.net trace information is all integrated together and have a single view of that data will put this back I'm not limited to viewing information the output window I can also included within a page trace.

 The application open up my default.aspx and add the trace attribute save it and I'll run the page again I'll click on the webpage trace listener and I can scroll down here and see that the trace messages from that component are available within the trace information for the page got a nice it gives you a nice unified view of all of the trace information that is generated by the application whether generated by ASP.net or an outside component quantity one of the thing here, scroll down and disable the debug mode by setting the false will save that middle restart the application without debugging all select the webpage trace listener and once again come back and show you that the output window does not include the trace information this is important because a deployed application will not execute in debug mode and so there's no place for that debug information to go but you can still use trace information and output to different listeners and be able to gather it in different ways




Summery

Okay so that's a pretty convoluted code for using tracing features in your application but having consolidated view of everything going on in your application including custom messages that you add to the next can be enormously useful when you need to find a problem for monitoring application best of all their even more ways to monitor your code

Listeners : 7





From a component will also be written to the ASP.net trace okay logo confusing but it's just capturing messages that are going to ASP.net trace what it does is it let you integrate ASP.net tracing techniques with the system.diagnostics tracing techniques tried all the trace messages to a single tracing output is a consolidated view of everything that is going on within your application you can use it to do things like track the flow of execution for an application display data critical points throughout it web.

 Forms life cycle and you can discover how web forms interact with various other components in your application to think a look at how you can put this trace listener to work to direct trace messages from a component to an ASP.net webpage you need to configure the webpage trace listener in the web.config file type this trace element within the system.diagnostics that creates a listener called web listener that's a name that I choose and it references that webpage trace listener to this makes that listener available for this application is external component that will provide trace information it uses the system.diagnostics namespace and it just defines a very simple customer class in which all of the action takes place within the constructor the constructor receives.

A custom name string we check to see whether or not the length of that string is equal to zero if it is then we write out a message using the system.diagnostics.trace right line method indicated his blank and we specify where this message is coming from whether or not the names blank we also write out another message saying that the customers create a very simple example but the idea here is that because this customer object is within the app code folder it's a separate component that can send messages to ASP.net.

Typically if we included code like this it would just output it to the components trace listeners this is the kind of code that could appear in any.net component including ones that aren't necessarily intended for use with an ASP.net application what's different here is that the webpage trace listener what you receive the trace output from such components within your ASP.net applications and integrated together with the ASP.net trace messages the messages that are generated from the webpage itself now to enable tracing and components that use the system.diagnostics tracing you can use a compiler switch when you compile the application or you can make an entry in the config file for the component to turn that switch on automatically.

When the codes compiled so go back over the web.config file and scroll down here and notice that I have this compiler's element with a couple of compiler elements as child elements and all contained within the system.co.element the idea here is that because the code for this component the customer component is in the app code folder is automatically compiled when ASP.net application is compiled and a reference is automatically added to the web application.


Tuesday, February 5, 2013

Listeners : 6




 We flush the listeners buffer that just clears all the messages and put them where they need to be the last step is to display that message on the page and then do a cleanup that just ties up all the loose ends of the listeners now access the application first welcome back of the web.config make sure that I have my switches set and I do Boolean switch is set to once.

 It's true and the multi-switch is set to four which is going to be verbose just means of this good output all the messages I'll go and run the application and I'll click on the trace which is an trace listeners like there scroll down a bit here and you can see that we have some output text based on the settings of the switches and the information that we generated within the page obviously probably not going to add this kind of information to the page but you could but you could also do other things conditionally.

Based on the switch settings that you specify within web.config elbow back over to Visual Studio else like the tracing project will go ahead and stop the application to refresh the list of files and we can see that we have a new file here called trace log.txt I can open that up and you can see that we have that output which was sent to the text writer listener similarly you can go into the Windows event log and see that there are messages that are stored there because we used an event log listener right let's go back over the web.config.

And let's set the Boolean switch to zero and let's set this switch to one and I'll go ahead and run the application again will select default.aspx and that's the start of page and click on the link and I can see the results are different in the page on the back of the Visual Studio it tells me the trace log.txt changed Saul reload that and take a look at it and now has different contents based on the conditions of the switches that are set within web.config that even though most of the messages were written using only the pages trace.write method and didn't use the system.diagnostics.trace object all the messages were routed to the listeners because the web.config file set.

The right to diagnostics trace option to true there's another trace listener that is a part of system.diagnostics the system.Web namespace includes a trace listener drive type called webpage trace listener what it does is it serves as a counterpart to the right to diagnostics trace what this means is that the webpage trace listener what you go the other way and monitor components that use the system.diagnostics classes for tracing and captures the system.diagnostics.trace messages in ASP.net page traces when you add an instance of the webpage trace listener is added to the trace listeners collection and messages written to the.net diagnostics trace.

Listeners : 5





Will the convoluted but you get used to it after a while so I passed now has the path to the application and then we can knew of the file stream defining it as a motive either open Hate giving it the name of trace log and you put that within the application path now the text listeners to find and we go ahead and add it to the listeners collection of the trace object each listener that you define is going to require different steps to set it up.

 Because it's going to be sending its information to different media different devices different locations whatever you create you should tear down to the cleanup method takes care of clearing out the listeners from the trace collection to the clear method takes care of clearing out all the listeners that are associated with the trace object and it closes down any of the listeners when you execute the close method it flushes any messages that have been cached and writes them to whatever output media is appropriate for that type of listener.

Can take a look at how to use these listeners over into the code behind my default.aspx page and scroll down to the right to listeners method this procedure shows how you can use the listeners and switches in your code the first thing it does is calls initialize listener method on the trace listen object in order to initialize listeners that news of the string builder which organ he used to build the string in order to display on the page at this point were ready to start outputting messages so we append some text to that string builder but we do it conditionally based on whether or not that Boolean.

 Switch is enabled or not if it is enabled then we went to string it is not enabled that we don't write the string and then we can do some conditional operations based on whether that's which is enabled in this case really do a trace right as well as a right line to the trace object the rest of the code within this procedure just test to see whether switches are enabled and outputs various messages this line of code shows how you can test to see whether the multi-switch list this line of code shows how you can test to see whether the multi-switch trace.

 Which is set to at least the error level and if it is then it's going to output a message it sent a warning it's good output that message and this one and if it is set to the info level or better than allow put this information to the big message of this procedure is to show how you can conditionally output different kinds of information based on whether a particular switch is set or sent to a specific level right at the end of the method we call the two string method of the string builder and that places that information within that message variable and then.

Listeners : 4





The settings there noticed that system.diagnostics is a child of the configuration element so I'm output those settings right appear and all same technique can create trace switches in code thereafter all just classes within the.net framework but if you put them within the web.config A lot more flexibility to make changes to them and add new ones without having to compile your code which if set the trace switches then you can create trace listeners in your code to output trace messages the trace listen class defines several objects.

Is an event log trace listener a text writer trace listener Boolean switch and trace which we talked about those the code that implements these is a separate class and so is located within the app code directory although had open up that code file and you can see there's a lot of code in order to implement these listeners first of all the various listeners that I'm using require the system.diagnostics namespace as well as system.

I'll input output in the code defines these listeners I define to trace listeners one an event log trace listener and the other a text writer trace listener and I also define a couple of switches trace switch and Boolean switch the initialize listener class initializes the two trace switches using the names that they were defined with in the web.config file then ASP will be able to look up the activation level of those two switches at runtime so I instantiate a new trace switch object using the name from the web.config and then give it a friendly name is just a demo trace which and I do the same thing for Boolean.

Switch next the code clears the listeners collection you have had other listeners that were enabled browser code or within other configuration files but this starts with a clean slate that creates the two listeners and want to use the event log trace listener it news up that object and gives it friendly text identify and then adds that listener to the collection of listeners that are associated with the trace object in the code creates the trace writer trace listener object but this requires a little bit more work to do first of all we need to get a location for the output for this because it's good to save it to a text file.

Three is the HTTP context object that's available within all ASP.net applications get a reference to the current context and the request object and refer to the physical application path this can return the physical location of the application on the server wait a second what we just use the request object directly or we can't because the current class that this is being used within is not part of a class that inherits from the system.Web.UI.page class to the request object is not automatically available but because this code is executing within a web application we do have access to it through this HTTP context object.
 

Sample text

Sample Text

Total Pageviews