ASP.NET
  Home arrow ASP.NET arrow Page 3 - Programming an In-Text Advertising System ...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

Programming an In-Text Advertising System under ASP.NET 3.5
By: Xianzhong Zhu
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2009-01-21

    Table of Contents:
  • Programming an In-Text Advertising System under ASP.NET 3.5
  • The JavaScript files
  • The Server-side Programming
  • The Three Generic Handlers Related Programming

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Programming an In-Text Advertising System under ASP.NET 3.5 - The Server-side Programming


    (Page 3 of 4 )

    When you download the source code accompanying this article, you will see that there are three .cs files, i.e. Tools.cs, ValidateCode.cs, and Sql. under the sub-folder App_Code of the sample website. First, the Tools.cs file holds the definition of the Tools class, which contains a static method named Encrypt(). This method is used to encrypt the password of the logged-in user, which used the DES encrypting algorithm provided by .NET framework. Since this strays from the main point of this article, we won’t dwell upon it any more. You can refer to the source code for details.

    Second, the ValidateCode.cs file is used to generate the verifying code that you usually see on today’s web pages, which will be discussed in the next section below.

    Finally, let’s take a look at the sql.cs file, which encapsulates the server-side database-related operations. On the whole, the Sql class defines four methods named getMyDataSet, ExecuteSql, getDataSet, and exec, respectively. Below I first list the codes for the getMyDataSet method:

    public DataSet getMyDataSet(string sql)

    {

    command.Connection = Con;//setup the command object

    command.CommandText = sql;

    DataSet dt = new DataSet();//initialize the DataSet object

    SqlDataAdapter da = new SqlDataAdapter(command);

    Con.Open();

    da.Fill(dt);//execute sentence

    command.Connection.Close();//Close sentence

    return dt;

    }

    Next, the ExecuteSql method is responsible for executing a non-query typed SQL query. Below I've indicated the related coding:

    public int ExecuteSql(string sql)

    {

    if (Con.State != ConnectionState.Open)

    Con.Open();//if the connection is closed, then open it

    SqlCommand Com = new SqlCommand(sql, Con);

    int result = Com.ExecuteNonQuery();//execute non-query sql clause

    Con.Close();

    return result;

    }

    Since the above code is basic database operation programming using C#, and there are also necessary comments, it’s unnecessary to give any further  explanation. The implementations of the other two methods, i.e. getDataSet and exec, are given as follows:

    public DataSet getDataSet(string produreName)

    {

    command.Connection = Con;//assign the connection object

    command.CommandType = CommandType.StoredProcedure;//specify the execute type

    command.CommandText = produreName;//assign the name of the SP to be executed

    DataSet dt = new DataSet();

    SqlDataAdapter da = new SqlDataAdapter(command);

    Con.Open();//open the connection

    da.Fill(dt);//fill data

    command.Connection.Close();

    return dt;//return the dataset

    }

    //Input:name of the stored procedure; execute non-query sql clause

    public bool exec(string produreName)

    {

    bool flag = false;//identify whether the task is finished as expected; set to false at the beginning

    command.Connection = Con;

    command.CommandType = CommandType.StoredProcedure;

    command.CommandText = produreName;

    if (Con.State == ConnectionState.Closed) Con.Open();

    try

    {

    command.ExecuteNonQuery();//execute the SP

    flag = true;//succeed in execution

    }

    finally

    {

    command.Connection.Close();//close the connection

    }

    return flag;

    }

    Since I've provided detailed comments between the lines, we will not discuss these further. 

    Next, we’ll shift our attention to discussing the three generic handlers that still need to be defined on the server side.

    More ASP.NET Articles
    More By Xianzhong Zhu


     

    ASP.NET ARTICLES

    - Adding Content to a Static ASP.NET Website
    - Building a Static ASP.NET Website in a Basic...
    - Develop Your First ASP.NET Website with Visu...
    - Run ASP.NET in Windows XP Home with Cassini ...
    - How to Test a Web Application
    - How to Add Code and Validation Controls to a...
    - Working in Source and Split Views to Build a...
    - How to Build a Web Form for a One-Page Web A...
    - How to Develop a One-Page Web Application
    - An ASP.NET Web Application in Action
    - Developing ASP.NET Web Applications
    - An Introduction to ASP.NET Web Programming
    - Introduction to the ADO.NET Entity Framework...
    - Completing an In-Text Advertising System und...
    - Programming an In-Text Advertising System un...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek