Skip to main content

Posts

Showing posts from February, 2008

Configuration namespace and reading settings from the Configuration file,app.config,web.config

This one always catches me out. There are a few different ways to read settings in from a .config file. The confusion for me occurs when reading from certain sections and from config files other than ones for the currently running application. The easiest example is reading settings from the currently running application, from within it's own code. You can access the AppSettings Section <configuration><appSettings> <add key="hostname1" value="localhost"/><add key="hostname2" value="othername"/></appSettings></configuration> using: NameValueCollection appSettings = ConfigurationManager.AppSettings; foreach(string key in appSettings.AllKeys) Console.WriteLine(key + " " + appSettings[key]); So now you've all the keys in the AppSettings section i.e. "hostname1" and "hostname" and all their values accessed with appSettings[key] . Note: First you must add a reference to 'Sys...

ASP.NET HttpHandler how to

HttpHandlers are class which extend HttpHandler and which IIS recognises as the classes to use to handle errors etc. The HttpHandler class is usually stored inside a .ashx file. You can create your on .ashx and place it in you web app root dir, it will be entered whenever a request comes in from the client. If you do not want to show your HttpHandler file code in your web app then you can hide it in a dll see details below. How to hide the . ashx with a HttpHandler I'll describe here how to create a handler for a file with the extension .ashx, it's coincidental I require a HttpHandler in my web.config in order to alias my .ashx file which is too a HttpHandler. Note: Before you can compile a HttpHandler into a dll you must remove the directive at the start of the .ashx file e.g. delete this line <%@ WebHandler Language="C#" Class="MyWebHandler" %> If you fail to do this your .ashx code will not appear in your dll and you will not be able t...

Remoting, Remote Computing

Remote Computing http://del.icio.us/rss/learnerplates/remoting http://del.icio.us/search/?fr=del_icio_us&p=remoting&type=user There are 2 main ways in .NET to invoke a method and/or create an instance of an object on machine other than the one your 1. Webservices 2. .NET Remoting. 1. Webservices allow the client to communicate with the server be emitting an receiving XML, these XML messages are first wrapped on both the client and server side into SOAP envelopes..NET Remoting on the other hand allows a remote client to invoke a method through Proxy classes. 2. .NET Remoting You can access remote objects in 2 ways, by reference and by value. The first manipulates the actual original object on the server(the objects class must be MarshalByRefObject) , the second a copy of the original object is used which means any changes made will only effect the local copy, copy on the client, of the object (the objects class must be Serializable). The communication between Server and Client i...