encrypt and decrypt app.config in .NET 2.0

To encrypt, decrypt app.config file… private void button1_Click(object sender, EventArgs e){ UnProtectSection(”connectionStrings”);} private void button2_Click(object sender, EventArgs e){ ProtectSection(”connectionStrings”,“DataProtectionConfigurationProvider”);} private void ProtectSection(string sectionName, string provider){ Configuration config = ConfigurationManager. OpenExeConfiguration( ConfigurationUserLevel.None); ConfigurationSection section = [...]

To XSLT a large file (.NET1.1)

To XSLT a large file use XPathDocument rather than XmlDocument, e.g. Slower: Me.m_oldStream.Position = 0Dim xsl As New Xml.Xsl.XslTransformxsl.Load(Me.m_xsltFilePath)Dim xDoc As New Xml.XmlDocumentxDoc.Load(Me.m_oldStream)xsl.Transform(xDoc, Nothing, Me.m_newStream, Nothing)Me.m_newStream.Flush() Faster: Me.m_oldStream.Position = 0Dim xslt As XslTransform = New XslTransformxslt.Load(Me.m_xsltFilePath)Dim doc As XPathDocument = New XPathDocument(Me.m_oldStream)xslt.Transform(doc, Nothing, Me.m_newStream, Nothing)Me.m_newStream.Flush() http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/ScaleNetChapt09.asp claims 20-30% faster processing.In one extreme example of a project I have worked on, [...]

Accessing web service from behind proxy

If you are going to (via a proxy server) connect to a web service on the Internet you may need to do the following (VB.NET): Dim s As Service1 s = New Service1 s.Credentials = System.Net.CredentialCache.DefaultCredentials s.Proxy = New System.Net.WebProxy(”internal proxy server address”, 80) s.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials

Generating truly random numbers with multiple simultaneous request

The Random Class, given a constant seed will always generate the samesequence of numbers.Creating a Random object using the default constructor uses the current timeas the seed, so if you have multiple simultaneous requests and need to getdifferent numbers this approach will not work.A slightly cumbersome “fix” to generate a seed is shown below. Thisessential [...]

ASP.NET CustomValidator doesn’t fire ServerValidate event w hen input box is empty

ASP.NET valuator controls don’t validate empty input by default, this iswhat the RequiredFieldValidator is for… sometimes for customised inputvalidation you might not want this behaviour (e.g. if one of two input boxesmust be non-blank)… /// /// Overrides the default behaviour of CustomValidator to allow /// ServerValidate event to fire even if the input is blank./// public [...]

Using network load balancing (NLB) with transactional MSMQ message

Want to send transactional messages using DIRECT format TCP to multiple server through a network load balancer? You can’t. Simple as that. See MSDN article ID 899611 Essentially you could have a single message delivered to more than one server which could be very bad news if they contain something like a “transfer money” message… From [...]