Tuesday, March 3, 2009
Google Adsense SMS
a.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("Keep Text Messaging FREE AND SAFE click our ad below.");
Response.Write("
");
// Response.Write("Visit www.mobilegreatness.com From your PC to get your Free SMS widget");
// Response.Write("To support us, please click on below google ad");
//Response.Write("
");
string googleScheme = "http://";
string googleHost = Server.UrlEncode(googleScheme + Request.ServerVariables["HTTP_HOST"]);
double googleTime = (DateTime.Now - new
DateTime(1970, 1, 1)).TotalSeconds;
double googleDt = (1000 * googleTime) + Math.Round(1000 * Timer() -
(int)Timer());
string https = Request.ServerVariables["HTTPS"];
if (https.IndexOf("on") > -1)
{
googleScheme = "https://";
}
string googleAdUrl = "http://pagead2.googlesyndication.com/pagead/ads?ad_type=text_image&channel=" +
"&client=ca-mb-pub-3965045331381248" +
"&color_border="+googleColor("555555", googleTime) +
"&color_bg="+ googleColor("EEEEEE", googleTime) +
"&color_link=" + googleColor("400058", googleTime) +
"&color_text=" + googleColor("000000", googleTime) +
"&color_url=" + googleColor("008000", googleTime) +
"&dt=" +googleDt +
"&format=mobile_single" +
"&host="+googleHost +
"&ip=" + Server.UrlEncode(Request.ServerVariables["REMOTE_ADDR"]) +
"&markup=xhtml&oe=utf8&output=xhtml" +
"&ref=" + Server.UrlEncode(Request.ServerVariables["HTTP_REFERER"])
+"&url=" + googleHost +
Server.UrlEncode(Request.ServerVariables["URL"]) +
"&useragent=" +
Server.UrlEncode(Request.ServerVariables["HTTP_USER_AGENT"]) +
googleScreenRes();
WebClient wc = new WebClient();
string googleAdOutput = wc.DownloadString(googleAdUrl);
Response.Write(googleAdOutput);
HttpWebRequest req = (HttpWebRequest)
WebRequest.Create(googleAdUrl);
HttpWebResponse resp = null;
try
{
req.Timeout =
Int32.Parse(ConfigurationManager.AppSettings["Google_Timeout_Msec"]);
resp = (HttpWebResponse)req.GetResponse();
Stream responseStream = resp.GetResponseStream();
StreamReader streamReader = new StreamReader(responseStream,
Encoding.UTF8);
googleAdOutput = streamReader.ReadToEnd();
}
catch (HttpException htex)
{
}
catch (Exception exception)
{
googleAdOutput = "";
}
finally
{
// According to MS doc. it's only necessary to close either
if (resp != null) {
resp.Close();
}
}
}
string googleColor(string value, double random)
{
string[] colorArray = value.Split(',');
return colorArray[(int)random % colorArray.Length];
}
string googleScreenRes()
{
string screenRes = Request.ServerVariables["HTTP_UA_PIXELS"];
char delimiter = 'x';
if (screenRes == null)
{
screenRes = Request.ServerVariables["HTTP_X_UP_DEVCAP_SCREENPIXELS"];
delimiter = ',';
}
if (screenRes != null)
{
string[] resArray = screenRes.Split(delimiter);
if (resArray.GetUpperBound(0) + 1 == 2)
{
return "&u_w=" + resArray[0] + "&u_h=" + resArray[1];
}
}
return "";
}
double Timer()
{
return (DateTime.Now - DateTime.Now.Date).TotalSeconds;
}
}
a.aspx
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.Web" %>
<% double googleTime = (DateTime.Now - new DateTime(1970,1,1)).TotalSeconds; double googleDt = (1000 * googleTime) + Math.Round(1000 * Timer() -(int)Timer()); string googleScheme = "http://"; string https = Request.ServerVariables["HTTPS"]; if (https.IndexOf("on") > -1)
{
googleScheme = "https://";
}
string googleHost = Server.UrlEncode(googleScheme +Request.ServerVariables["HTTP_HOST"]);
string googleAdOutput = "";
string googleAdUrl = "http://pagead2.googlesyndication.com/pagead/ads?" +
"ad_type=text_image" +
"&channel=" +
"&client=ca-mb-pub-3965045331381248" +
"&color_border=" + googleColor("555555", googleTime) +
"&color_bg=" + googleColor("EEEEEE", googleTime) +
"&color_link=" + googleColor("400058", googleTime) +
"&color_text=" + googleColor("000000", googleTime) +
"&color_url=" + googleColor("008000", googleTime) +
"&dt=" + googleDt +
"&format=mobile_single" +
"&host=" + googleHost +
"&ip=" + Server.UrlEncode(Request.ServerVariables["REMOTE_ADDR"]) +
"&markup=xhtml" +
"&oe=utf8" +
"&output=xhtml" +
"&ref=" + Server.UrlEncode(Request.ServerVariables["HTTP_REFERER"]) +
"&url=" + googleHost +
Server.UrlEncode(Request.ServerVariables["URL"]) +
"&useragent=" +
Server.UrlEncode(Request.ServerVariables["HTTP_USER_AGENT"]) +
googleScreenRes();
HttpWebRequest req = (HttpWebRequest)
WebRequest.Create(googleAdUrl);
HttpWebResponse resp;
try {
req.Timeout =
Int32.Parse(ConfigurationManager.AppSettings["Google_Timeout_Msec"]);
resp = (HttpWebResponse)req.GetResponse();
Stream responseStream = resp.GetResponseStream();
StreamReader streamReader = new StreamReader(responseStream,Encoding.UTF8);
googleAdOutput = streamReader.ReadToEnd();
resp.Close();
} catch (Exception exception) {
// Something went wrong. This is a good place to log theexception.
googleAdOutput = "";
}
%> -->
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment