Completing an In-Text Advertising System under an ASP.NET 3.5 Environment - The Member Center: the siteUser.aspx page
(Page 3 of 5 )
The siteUser.aspx page serves as the member center for the website owner, where you can view your ad-related data, as well as obtain the ad code (which directs you as to where and how to put the code inside your own web page to advertise your products). Figure 2 indicates one of the running time snapshots of the page.
Figure 2—The siteUser.aspx page serves as the member center of the website owner
_html_4e666ecb.png)
The whole layout of the page is simple, with a GridView control to display the ad- related data and a TextBox control (with the TextMode attribute set to MultiLine) to show the ad code.
Next, let’s take a quick look at the code behind the above page, as follows:
public partial class siteUser : System.Web.UI.Page
{
public string code = "";//the ad code
protected void Page_Load(object sender, EventArgs e)
{
if (!User.Identity.IsAuthenticated) Response.Redirect("login.aspx");//if not logged in, then go to page login.aspx
code = "<script type ="text/javascript" >var username='"+ User.Identity.Name+"'";
code+= "; </script><script type="text/javascript" src="js/getad.js"></script>";
TextBox1.Text = code;
string username = User.Identity.Name;//the user account
Sql s = new Sql();
//get the user's ad popularizing related data and show them
GridView1.DataSource = s.getMyDataSet("select * from hit where username='"+username +"'");
GridView1.DataBind();
}
}
Here, if the current user has not logged in, then he is redirected to the "Login.aspx" page; otherwise, the code sets up the contents of the TextBox control with the hard-coded script, and then obtains the current user specific ad data and shows it inside the GridView control. That’s all.
Next, let’s look at the system administrator-related pages.
Next: Manage the Ad Keywords >>
More ASP.NET Articles
More By Xianzhong Zhu