Skip to main content

Posts

Showing posts from 2006

dotNET - Use app.config ApplicationSettings and UserSettings

When using Settings in an Assembly or .exe you can use the Settings Designer to generate a config file using Settings. The Settings Designer provides a wrapper class which allows you to provide defaults and access the config data using Properties. But what if you're not working inside that Assembly or .exe? this presents a problem. If your loading the Assembly externally and want to access that Assembly's .config file you'll probably wish to use something in the System.Configuration namespace... unfortunately it's not of much use if you've created the .config file from the Settings Designer in Visual Studio!! This is because the Designer creates Sections and ApplicationSettings and UserSettings, the System.Configuration namespace does not provide a method to access these (it has a method to access AppSettings which are a different thing. Below I've written a workaround which locates the app.config and accesses the ApplicationSettings and UserSettings using XML i...

Windows Miscellaneous

Virtual PC Creating a Virtual PC using another machines Virtual Hard Disk Make a copy of the other machines .vhd file. Copy to the local machine and point the new Virtual PC to the .vhd. SID will have to be run on the new Virtual PC in order to change the name of the machine, as it will still have the name of the original machine the vhd was taken from. http://www.microsoft.com/technet/sysinternals/Security/NewSid.mspx HTML DOM Inspector http://www.sharewareconnection.com/download-ie-dom-inspector-from-sharecon.html

dotNET - VS 2005 Web Deployment Projects + Installer (MSI) creation

You've got your Web Project in Visual Studio and you want to create a way to provide it as an installation. There are 2 ways to do this: 1. Create a Web Deployment Project from your Web Project and then use the output of this as the input to another project, a Setup Project. After you've achieved this you'll have an MSI installer file which has configurable elements, these configurable elements will be dictated by yourself when creating the Web Deployment Project and the Setup Project. 2. Create a WebSetup project from your Web Project. After you've achieved this you'll have an MSI installer file. Option 2 is the simpler option. The difference between the 2 options is that the first provides extra control using the Deployment project, such things a MSBuild and assembly type deployment. If you choose option 1 then: You can quickly create a Web Deployment Project by right-clicking the Web Project in the Visual Studio Solution Explorer. This will copy the contents of y...

IIS admininstration Miscellaneous

http://feeds.delicious.com/rss/learnerplates/iis How to access the IIS Metadase programmatically. Parser for IIS logs A script to extract data from log files (can be IIS log files) using SQL Query format. http://www.microsoft.com/technet/community/columns/profwin/pw0505.mspx The script can be downloaded at http://www.microsoft.com/downloads/details.aspx?FamilyID=890cd06b-abf8-4c25-91b2-f8d975cf8c07&displaylang=en

Cookies and FormsAuthentication

Cookies Cookies are simply a file stored in the client machine which are sent up and down to and from the server with every Request and Response. The Cookie is used to store some client information such as details of their past session. It allows the Client to return to a webpage and have information already available to them without having to start from scratch. The Cookie is first sent down from the Server and is stored somewhere on the Client's hard-drive. It's up to the Web Application developer to do the Cookie processing on the Server side. The Cookie can be accessed from the Request as the Cookie is a property of the HttpRequest, Request.Cookie["cookiename"]; One problem I've encountered with Cookies is that all the cookies associated with your application get Posted from the Client on each Request, this adds to the amount of data sent as you can imagine. There is a solution however, in order to ensure a Cookie is only sent from Client to Server when a cert...

Setup Programs Installer creation using VS2005

Setup Programs Installer creation using VS2005 Getting Started with Setup Projects (SimpleTalk). Visual Studio Setup Projects and Custom Actions (Simple Talk). Updates to Setup Projects (SimpleTalk). To create an Installer using Visual Studio you must create a Setup Project. A setup project contents are files and outputs of other projects in the solution. The Setup Project template can be found in the Visual Studio New Project dialog under Other Projects->Setup and Deployment->Setup Project. Tip! To debug installation or just see what's happening in the background and view system variable values use the msiexec logger, it logs everything that's happening on installation, it can also be used for uninstall install: msiexec /i yourinstaller .msi /l* yourinstaller .log or verbose msiexec /i yourinstaller .msi /l*v yourinstaller .log uninstall: msiexec /uninstall yourinstaller .msi /l* yourinstaller .log or verbose msiexec /uninstall yourinstaller .msi /l*v yourinstaller .lo...

Miscellaneous

New Assignment instead of Virtual/Override The "new" keyword can be used with methods, it provides a type of inheritance similar to polymorphism. class Program { static void Main(string[] args) { BaseClass bc = new BaseClass(); ChildClass cc = new ChildClass(); bc.Foo(); bc.Bar(); Console.WriteLine("======================="); ((BaseClass)cc).Foo(); ((BaseClass)cc).Bar(); Console.WriteLine("======================="); cc.Foo(); cc.Bar(); Console.WriteLine("======================="); Console.ReadLine(); } } class BaseClass { public void Foo() { Console.WriteLine("BaseClass.Foo"); } public virtual void Bar() { Console.WriteLine("BaseClass.Bar"); } } class ChildClass : BaseClass { new public void Foo() { ...

dotNET Project Template and Addin Creation

Project and Item Templates Create Reusable Project and Item Templates for the development team . Project Template Creation Creation of a project or item template is pretty straight forward. Use the File->Export Template to create the template, the wizard will ask you which Project you wish to base your Template on, this will result in the contents of that Project being added to the Template. Note that depending on the type of Project you select will determine where the Template appears in the File->New Project dialog. i.e. If you base your Template on a Website Project in VB then the Template will appear in the File-New Website and under the VB section in the File->New Project dialog. Create a project like the one found at http://msdn.microsoft.com/msdnmag/issues/06/01/CodeTemplates/default.aspx . The Template is just a zip file with an extra xml file within, the xml file describes what to add to the project when a user uses File->New Project. If you wish to generate Projec...

dotNET Custom Controls and Resource Scripts

Custom Controls are Web Controls, (TextFields, Labels etc) which are customized by you. The Custom Controls can then added to your website by adding the assembly containing the Custom Control or used through Visual Studio ASPX editor by created adding the Custom Control to the ToolBox (this is done by Right-Clicking the ToolBox and selecting Choose Items... then select the locate of the Assembly containing the Custom Control. An example of a very simple Custom Control implementation can be found here Simple Custom Control (msdn) Additionally you can embed some of you JScript code in a .js file instead of in the aspx page itself. This js file should be added to you Custom Control project as an Embedded Resource (This means the JScript code is embedded in the resultant assembly. When this assembly is referenced by a website project it will be able to access the JScript functionality (??). To add the js file add it to the Custom Control Project as a Resource. Add a new Resource file to t...

dotNET Custom Configuration Handlers

So you want to add some configurable content to your application/Web application. The place for your data is in the configuration file, app.config or web.config. You could put it in the AppSettings, a small problem with this is it uses Key/Value collections which means that the Keys must be unique, that's not the end of the world but you may want to access a complete section in the config file and sort them or something. The alternative is to create your own section in the config file. To access this you'll need to create your own Handler Class. I'll explain the settings in the config file followed by the Handler Class and then how to access it. Custom Configuration Handlers on ASP.NET Forum

dotNET Web Application Stress Testing

Stress Testing ASP.NET Web Apps is all about simulation heavy usage and isolating bottlenecks. There are some Microsoft Tools available, see below. These tools allow you to create scenarios on your website, increase number of users and view the results. I'll report back with more information when I actually use these tools. For now this is just a placeholder. Microsoft Stress Test Tool, ACT, Application Center Test. Available from your Visual Studio Enterprise Edition DVD. Older Stress Test Tool, downloadable from msdn. http://www.microsoft.com/downloads/details.aspx? FamilyID=E2C0585A-062A-439E-A67D-75A89AA36495&displaylang=en"> Other useful resources could be Windows Performance Counters. These are Windows information that is available on Processes and Threads running. You can provide your own applications Performance Counter information be incrementing the Performance counter containers. The information is Viewable on the Perfmon.exe available on Windows machines. ht...

dotNET AppDomain and Remote Computing (Remoting)

AppDomain If for some reason you find that you're application cannot load an Type/Assembly at runtime it's usually because assembly lives somewhere different at runtime. For instance the host could do some copying to temporary locations at runtime, this can sometimes cause the references between assemblies to breakdown. So how do you tell the runtime to look somwhere else for the assembly well that's where the AppDomain comes into play. AppDomain refers to the namespace, space allocated in .NET memory/CLR in which your application is allowed to run. It's a security thing which prevents applications from cross communicating with each other. Reasons why you'd want to access the AppDomain can include: Need to manage the AppDomain i.e. delete or add resources from outside the applications namespace. If you wanted to ensure that certain assemblies for example were to be unloaded from another AppDomain at a certain point, you'd have to setup a new AppDomain and someho...

dotNET Serialization (XmlSerializer)

Serialization is the process of representing you Object in the form of text. This is a handy way to save out your Object structure to a file. The XML version is XmlSerializer, this creates an XML file structure of your Object. It will parse out all the public properties and save to XML. You can make your objects Serializable by simply adding the Serializable Attribute to each of your objects, when you call Serialize on that Object it and all of it's Child and Associated Objects which also have the Serializable Atribute will also be Serialized [Serializable] public class BaseballPlayer { [...] } To invoke Serialization on an Object you need a Formatter and a Stream. Or you can use XmlSerializer to perform the Serialization. see XMLSerializer and not expected type... (codeproject) Stream str = File.OpenWrite(filename); System.Runtime.Serialization.Formatters.Soap.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Soap.BinaryFormatter(); formatter.Serialize(s...

MSBuild

MSBuild Team Blog. MSBuild documentation (msdn) BuildTask creation MSBuild used by VS projects to build items. You can add build tasks to your Project file, either by directly adding to the .proj file or by creating .targets files with the task within and then adding this .targets file to your project file using the include option. The BuildTask can do anything you wish but the format which you call it is basically the same. To use a build task you must include the file that contains the BuildTask functionality. The BuildTask itself is just a class that extends Microsoft.Build.Utilities.Task . Compile it into a dll and include the dll in your project file with the UsingTask . The AssemblyFile points to the location and name of the task's assembly, AssemblyFileName can also be used but only requires the file name, this means the file must be in the GAC or in the installation of .NET. <pre> <usingtask taskname="SetupUtils.RegistryTask" assemblyfile="...