Hashim's Blogs

Tuesday, April 18, 2006

How to Add Custom Tag in Web.Config Page (ASP.NET)

How to Add Custom Tag in Web.Config Page (ASP.NET)
To add a custom tag to Web.config you need to first explicitly specify the new tag name in Web.config via the tag
For Example:





type="System.Configuration.NameValueFileSectionHandler,
System, Version=1.0.3300.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" />


...


This
tag indicates that we are going to be adding New tag named MyAppSettings.
Now we can add a tag to our Web.config file and
add tags to add application-wide parameters,
For Example:





type="System.Configuration.NameValueFileSectionHandler,
System, Version=1.0.3300.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" />





...

How to Read Custom Tag

To read this custom value from an ASP.NET Web page we use the following syntax:

ConfigurationSettings.GetConfig("MyAppSettings")("connString")

Thursday, February 10, 2005

How to prevent sending emails without subject in Outlook

1. Open your outlook
2. Press Alt+F11. This will open the Visual Basic editor
3. On the Left Pane, one can see "Project1", expand this, you can see “Microsoft
Office Outlook Objects”, expand this. Now one can see the “ThisOutLookSession”.
(If you are not seeing "Project1", press Ctrl+R or View-> Project
Explorer).
4. Click on “ThisOutLookSession”.
5. Copy and Paste the following code in the right pane.(Code Pane)
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim strSubject As String
strSubject = Item.Subject
If Len(strSubject) = 0 Then
Prompt$ = "Subject is Empty !!!, Are you sure? you want to send the Mail?"
If MsgBox(Prompt$, vbOKCancel + vbQuestion + vbSystemModal +
vbMsgBoxSetForeground, "Check for Subject:-") = vbCancel Then
Cancel = True
End If
End If
End Sub
6. Now close the VB editor. From now on , this macro will make sure you do not make
the mistake of sending an email without subject

Note: You need to enable macros in the outlook for this code snippet to work.

How to prevent sending emails without subject in Outlook

1. Open your outlook
2. Press Alt+F11. This will open the Visual Basic editor
3. On the Left Pane, one can see "Project1", expand this, you can see “Microsoft Office Outlook Objects”, expand this. Now one can see the “ThisOutLookSession”. (If you are not seeing "Project1", press Ctrl+R or View-> Project Explorer).
4. Click on “ThisOutLookSession”.
5. Copy and Paste the following code in the right pane.(Code Pane)
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim strSubject As String
strSubject = Item.Subject
If Len(strSubject) = 0 Then
Prompt$ = "Subject is Empty !!!, Are you sure? you want to send the Mail?"
If MsgBox(Prompt$, vbOKCancel + vbQuestion + vbSystemModal +
vbMsgBoxSetForeground, "Check for Subject:-") = vbCancel Then
Cancel = True
End If
End If
End Sub

6. Now close the VB editor. From now on , this macro will make sure you do not make the mistake of sending an email without subject
Note: You need to enable macros in the outlook for this code snippet to work.

How to prevent sending emails without subject in Outlook

1. Open your outlook2. Press Alt+F11. This will open the Visual Basic editor 3. On the Left Pane, one can see "Project1", expand this, you can see “Microsoft Office Outlook Objects”, expand this. Now one can see the “ThisOutLookSession”. (If you are not seeing "Project1", press Ctrl+R or View-> Project Explorer).4. Click on “ThisOutLookSession”.5. Copy and Paste the following code in the right pane.(Code Pane) Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) Dim strSubject As String strSubject = Item.Subject If Len(strSubject) = 0 Then Prompt$ = "Subject is Empty !!!, Are you sure? you want to send the Mail?" If MsgBox(Prompt$, vbOKCancel + vbQuestion + vbSystemModal + vbMsgBoxSetForeground, "Check for Subject:-") = vbCancel Then Cancel = True End If End If End Sub 6. Now close the VB editor. From now on , this macro will make sure you do not make the mistake of sending an email without subject Note: You need to enable macros in the outlook for this code snippet to work.

Sunday, December 26, 2004

GnuPG - The GNU Privacy Guard

Recently got a chance to work on GnuPG to send and recieve secure data.worked with GnuPG with C#.NET to encrypt/decrypt data.

GnuPG is GNU's tool for secure communication and data storage.It can be used to encrypt data and to create digital signatures.It includes an advanced key management facility and is compliantwith the proposed OpenPGP Internet standard as described in RFC2440.
GnuPG works best on GNU/Linux or *BSD systems. Most other Unicesare also supported but are not as well tested as the Free Unices.See http://www.gnupg.org/download/supported_systems.html for alist of systems which are known to work.

Because GnuPG does not use use any patented algorithms it is notby default fully compatible with PGP 2.x, which uses the patentedIDEA algorithm. See http://www.gnupg.org/why-not-idea.html formore information on this subject, including what to do if you arelegally entitled to use IDEA.

The default public key algorithms are DSA and Elgamal, but RSA isalso supported. Symmetric algorithms available are AES (with 128,192, and 256 bit keys), 3DES, Blowfish, CAST5 and Twofish. Digestalgorithms available are MD5, RIPEMD/160, SHA-1, SHA-256, SHA-384,and SHA-512. Compression algorithms available are ZIP, ZLIB, andBZIP2 (with libbz2 installed).

Wednesday, October 20, 2004

10 Steps to Help Secure SQL Server 2000

Friday, September 24, 2004

How to Share Session State Between Classic ASP and ASP.NET

Discusses how to share session state between classic ASP and Microsoft ASP.NET using Microsoft .NET Framework classes and the serialization feature of the .NET Framework. Sharing session state allows converting existing ASP applications to ASP.NET applications in stages while running the applications side by side

Read in Detail at : How to Share Session State Between Classic ASP and ASP.NET

Tuesday, August 24, 2004

Visual Studio .NET Technical Articles

Build Windows-based components and applications, create scripts, develop Web sites and applications, and manage source code with Visual Studio .NET and the individual tools and languages it contains.

This can be found at: Visual Studio .NET Technical Articles

Tuesday, August 17, 2004

Visual Sudio 2005 Beta Documentation

The .NET Framework class library is a library of classes, interfaces, and value types that are included in the Microsoft .NET Framework SDK. This library provides access to system functionality and is designed to be the foundation on which .NET Framework applications, components, and controls are built.

This can be found at: .NET 2.0 Reference Docs

Creating a Scrollable DataGrid Web Server Control

A most common question in many of the newsgroups and message board is “how to have a scrollable DataGrid” in a web page. In this article you can see how to create a scrollable DataGrid in a web page. By default DataGrid (Web Server control) doesn’t provide any features for scrolling. But this can be done with help of Cascading Style Sheet (CSS). CSS contains a property called “Overflow” which can used for this purposes.

Nice artical to read :

Creating a Scrollable DataGrid Web Server Control

How to use InsertAfter() with XmlDOM.

The InsertAfter() is a great function if you want to add elements to an already existing file. In this short example you will see how easily you can do this. Let's see how the XML file looks like.


see :How to use InsertAfter() with XmlDOM.

Friday, July 30, 2004

Consuming Webservices over HTTPS (SSL)

When Webservices are used, a common concern is security: SOAP messages are transferred in plain text over the network, so anyone with a sniffer could intercept the SOAP message and read it. In my opinion this could happen also to binary data, but probably it requires a little bit more hacker skills. So a solution is to use HTTPS (SSL) instead of HTTP, so the communication is encrypted. To accomplish this, you need to get and install a certificate (issued by a Certificate Authority) on your webserver. In a production environment you would buy a certificate from Verisign or another well known CA, or you would install your own CA, which is a component of Windows Server. If you only want to play with HTTPS, SSL and certificates or your project is in the development phase, you can also generate a test certificate using the MakeCert.exe tool (included in the .NET Framework SDK). After that you have to add this certificate to a website in IIS, and set a port which HTTPS should use.

When you browse to a HTTPS site, you probably get a dialog window asking you if you want to trust the certificate provided by the webserver. So the responsibility of accepting the certificate is handled by the user. Let's get back to the webservice scenario, if you want to invoke a webservice located on a webserver which uses SSL and HTTPS there is a problem. When you make the call from code, there is no dialog window popping up, and asking if you trust the certificate (luckily because this would be pretty ugly in server-side scenarios); probably you'll get following exception:
An unhandled exception of type 'System.Net.WebException' occurred in system.dll

Additional information: The underlying connection was closed: Could not establish trust relationship with remote server.

But there is a solution for this problem, you can solve this in your code by creating your own CertificatePolicy class (which implements the ICertificatePolicy interface). In this class you will have to write your own CheckValidationResult function that has to return true or false, like you would press yes or no in the dialog window. For development purposes I've created the following class which accepts all certificates, so you won't get the nasty WebException anymore:

public class TrustAllCertificatePolicy : System.Net.ICertificatePolicy
{
public TrustAllCertificatePolicy()
{}

public bool CheckValidationResult(ServicePoint sp,
X509Certificate cert,WebRequest req, int problem)
{
return true;
}
}

As you can see the CheckValidationResult function always returns true, so all certificates will be trusted. If you want to make this class a little bit more secure, you can add additional checks using the X509Certificate parameter for example. To use this CertificatePolicy, you'll have to tell the ServicePointManager to use it:
System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
This must be done (one time during the application life cycle) before making the call to your webservice.

Wednesday, July 28, 2004

J2EE vs. Microsoft.NET By Chad Vawter and Ed Roman (Good Article to Read)

J2EE vs. Microsoft.NET
A comparison of building XML-based web services
By Chad Vawter and Ed Roman June 2001
Prepared for Sun Microsystems, Inc.

J2EE vs. Microsoft.NET A comparison of building XML-based web services

In this whitepaper, the authors has made a powerful comparison between the two choices that businesses have for building XML-based web services: the Java 2 Platform, Enterprise Edition (J2EE)1 , built by Sun Microsystems and other industry players, and Microsoft.NET2, built by Microsoft Corporation.

Tuesday, July 20, 2004

Lock the system without using CTRL+ALT+DEL

Hi,

This is a interesting piece of info that you can use to lock your
work-stations without using the combo key "CTRL- ALT- DEL"
If CTRL-ALT-DELETE seems like too much of a hassle, try this instead:
1. Right click an empty spot on the desktop, point to New and click
Shortcut.
2. In the Create Shortcut dialog box, type the following into the Type the
location of the item text box:
"rundll32 user32.dll,LockWorkStation" // remove quotes while typing
3. Click Next.
4. In the Select a Title for the Program dialog box, type "Lock Desktop" in
the Type a name for this shortcut text box.
5. Click Finish.

Simple Encryption and Decryption Using VB.NET

Imports System.Security.Cryptography
Imports System.Text
******* Encrypt the Data *******
Public Function GetEncryptedData(ByVal Data As String) As String
Dim shaM As New SHA1Managed
Convert.ToBase64String(shaM.ComputeHash(Encoding.ASCII.GetBytes(Data)))
Dim eNC_data() As Byte = ASCIIEncoding.ASCII.GetBytes(Data)
Dim eNC_str As String = Convert.ToBase64String(eNC_data)
GetEncryptedData = eNC_str
End Function
******* Decrypt the Data *******
Public Function GetDecryptedData(ByVal Data As String) As String
Dim dEC_data() As Byte = Convert.FromBase64String(Data)
Dim dEC_Str As String = ASCIIEncoding.ASCII.GetString(dEC_data)
GetDecryptedData = dEC_Str
End Function
*********************************

The above code snippet demonstrates simple encryption/Decryption a given string very use full in password encryption.
The function uses SHA1 to Compute the SHA1 hash for the input data.
The hash is used as a unique value of fixed size representing a large amount of data.
The hash size for the SHA1 algorithm is 160 bits.
This function Imports the  System.Security.Cryptography and System.Text namespace for this.