我编写了一个代码来充当网络计数器。它在 OutPutStream 中生成 javascript 输出,因此我可以在另一个网站中使用该脚本为其提供免费的网站计数器。问题是,当我想获取引荐来源网址时,它返回放置脚本的页面而不是真正的引荐来源网址。这是我的代码:
正文中的html代码:
<script type="text/javascript" language="javascript" src="counter.aspx?siteid=2"></script>
和 counter.aspx.cs :
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class counter : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "text/javascript";
UICulture = "en-US";
Culture = "en-US";
int siteid = int.Parse(Request.QueryString["siteid"].ToString());
string pubIp = new System.Net.WebClient().DownloadString("https://api.ipify.org");
var ipResponse = GetCountryByIP(pubIp);
HttpBrowserCapabilities browse = Request.Browser;
string platform = browse.Platform;
string browsername = browse.Browser;
Counter cnt = new Counter();
var counter = cnt.GetCounter(siteid, DateTime.Now, pubIp, Request.UrlReferrer.ToString(), platform, browsername, "", ipResponse.Country);
string text = "document.write('<div id=\"ShortCounter\" style=\" margin: 0px auto;width: 100px;min-height: 100px;font-family: Tahoma;font-size: x-small;background-color:" + counter.BackColor + ";color:" + counter.color + ";border:" + counter.BorderSize + "px " + counter.BorderStyle + " " + counter.BorderColor + ";\">" +
"<div style=\"padding: 8px;\">" +
"You Are Visitor Number:<br />" +
counter.CounterNumber.ToString("N0") +
"<br />" +
"Today" +
"<br />" +
counter.Today.ToString("N0") +
"<br />" +
"This Week" +
"<br />" +
counter.ThisWeek.ToString("N0") +
"<br />" +
"This Month" +
"<br />" +
counter.ThisMounth.ToString("N0") +
"<br />" +
"</div>" +
"<div style=\"width: 100%; background-color: darkred; text-align: center; padding-top: 2px; padding-bottom: 2px;\">" +
Request.UrlReferrer.ToString() +
"</div>');";
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(text);
Response.OutputStream.Write(bytes, 0, bytes.Length);
}
问题是:假设我在 xyz.com(其他站点),然后单击链接并转到 zzz.com/1.html(我的站点)。zzz.com/1.html 页面包含我之前提到的脚本我想知道 zzz.com/1.html 引荐来源网址是 xyz.com 但我的 c# 页面显示我 zzz.com 作为引荐来源网址是有道理的。我怎么能得到 zzz.com/1.html 推荐人?!我希望解释已经足够了。
谢谢