Inside W3Hearts
Categories
Windows Programming
C#
Visual Basic 6.0 / .NET
C / C++ / Visual C++ (MFC , SDK)
Packaging & Deployment
Web Programming
ASP.NET
ASP.NET Webservices
PHP & MySQL
J2EE / Servlet / Struts
Client side coding
Javascript & AJAX
CSS
HTML / XHTML
Database
SQL Server
Oracle
MySQL
 
 
Use of Image Control to Prevent Automated Website Registrations Using Asp.NET
by Shashidhar P T
Jun 30th 08

Nowadays in all the site it is general that, to become a member user has to enter text that is displayed in an image after filling his general information. The image with text displayed is randomly generated for each registration. This is to make sure that user has created his own profile. This prevents automated generation to site.

Simple Way of Integrating Autogenerated Image with Text

Major Steps Involved to prevent automated website registrations

1. Generate a random string
2. Generate an image with the random string that was generated in the earlier step

Code to generate random string using inbuilt Random class

Code

public static string GenerateString()
{
int iSLength=0, iRN=0;
string sRString;
Random rR =new Random(System.DateTime.Now.Millisecond);
sRString = "";
while (iSLength < 5){
iRN = rR.Next(0, 86);
if(((iRN >= 0) && (iRN<= 9) || (iRN >= 65) && (iRN <= 86))){
sRString = sRString + (char)iRN;
iSLength = iSLength + 1;
}
}
return sRString;
}
 

 
In the above code you are generating a random number and that random number is converted to a character if the number is equal to or between 0 and 9, or between 65 and 86. You may notice that the number 65 corresponds to letter ‘A’ and you can calculate the number for character ‘Z’. The characters are concatenated to string variable until you reach the length of the string, in this sample length of the string is 4. The code for generating a string can be within a function so that it can be used while generating the image. 
Code to generate image with string
Code
Bitmap bmpImage=new Bitmap(80,25);
Graphics g=Graphics.FromImage(bmpImage);
g.Clear(Color.Red);
string sRS=GenerateString();
Session["sessionRS"]=sRS;
g.DrawString(sRS,new Font("Arial",14),new SolidBrush(Color.Black),2,2);
bmpImage.Save(Response.OutputStream,ImageFormat.Gif);
bmpImage.Dispose();
 
In the above code you can see GenerateString() method is called while the geneartion of the image and is outputted to response stream. This output is fed to the Image control that is used in the registration form.
Code to call the Image Control in registration form
Code
<asp:Image id=Image1 runat="server" ImageUrl="url-of-the-page-that-generates-image" />
 
url-of-the-page-that-generates-image : The form that generates the image with string is the URL of the Image Control in the registration form. This enables the generated image to be bound to the image control for display in the form.
To compare the string against keyed in by the user

If you observe the code of generating image with string, string is stored in session variable prior to creation of image. You can make use of the string stored in session variable to compare the string keyed in by user in form and display the error message if necessary. The above code for generating the image is placed within an “if” block which checks whether the user accesses the page for the first time. If the user is accessing the page for the first time then the image is generated, otherwise not. 

 
 
 

Threading with BackgroundWorker helper class
by Navaneeth.K.N
Jun 4th 08

You are developing an application which has a long running job. You run this job on the main thread and your GUI got hanged until the job finishes. Obviously you will think about running the process in a parallel thread which reports the work progress to main thread and display progress on the GUI. In this article we will discuss about using a helper class called BackgroundWorker which is included since .NET framework 2.0 to make multi threading more easier.

Introduction to threading

A small piece in execution can be called as a thread. Multithreading can be used to execute parallel tasks along with the other threads. Common example of multi threading is to keep GUI active when a long running process is executing. System.Threading is the namespace where classes related to threading are kept. To start a thread, initialize System.Threading.Thread instance and call it's Start() method. Here is how we create a simple thread.

Note
All the examples has System.Threading and System.ComponentModel namespaces included


Code

class Program
{
        static void Main(string[] args)
        {
            Thread t = new Thread(new ThreadStart(Worker));
            t.Start();
        }

        static void Worker()
        {
            Console.WriteLine("Hello from worker ! Current thread is {0}", Thread.CurrentThread.ManagedThreadId);
        }
}


ThreadStart is a delegate which represents the method to be executed when thread starts. Parameterizedthreadstart delegate can be used to pass any custom objects to the worker method.

Integrating Google Map to your ASP.NET Application
by Shashidhar P T
May 16th 08

This article explains how to integrate Google map to ASP.NET Application. We need to provide the latitude and longitude to Google map which in turn it will show the location of the person. Need to follow few steps to integrate Google map in your application.

Starting up

 

Step 1: First you need to get the Google map API key using the URL             http://code.google.com/apis/maps/signup.html.

Step 2: Store the API key in the web.config

Code
<add key="DevKey" value="ABQIAAAAQf-S7-zvKYryLbKB4_-loRQ8QYjC1Pz2TXTY0-7VkB1fk2ZdPBT9rAHuwxcfdrS9JlqWa9XCPlX8ww"/>


XP Style Navigation Bar Server Control with collection property and embedded resources
by Navaneeth.K.N
May 11th 08

This article explains how to create an ASP.NET server control which has a collection property and uses embedded web resources. In this, we will be creating an XP look and feel navigation server control.

Introduction

This article will focus on:
  •     How to create a server control with collection property
  •     Show collection editor on the designer for collection property
  •     Implement Web Resources concept
Here is a preview of the control rendered on "Internet Explorer 6.0".



 
 
© 2007 W3hearts.com
Home | Post Article | Start discussion | Join Community| Privacy policy