示例#1
0
    public static string Menu(string className = null, string id = null)
    {
        var sb = new StringBuilder();

        var context = new HttpContextWrapper(HttpContext.Current);
        IEnumerable <dynamic> data;

        using (var db = Database.Open(Functions.GetDbName()))
        {
            const string sqlSelect = "Select * From Menu Order By mOrderId DESC";
            data = db.Query(sqlSelect);
        }
        var pageName = context.GetRouteValue("PageName") ?? "default";

        pageName = "~/" + pageName.ToLower();
        if (pageName == "~/default")
        {
            pageName = "~/";
        }

        sb.Append("<ul class=\"" + className + "\" id=\"" + id + "\">");
        sb.Append(BuildMenu(data, 0, pageName));
        sb.Append("</ul>");

        return(sb.ToString());
    }
示例#2
0
    public static void SaveVisitorInfo()
    {
        var context         = new HttpContextWrapper(HttpContext.Current);
        var timeStamp       = DateTime.Now;
        var page            = context.GetRouteValue("PageName") ?? "Default";
        var browser         = context.Request.Browser.Browser;
        var browserVersion  = context.Request.Browser.Version;
        var operatingsystem = context.Request.Browser.Platform;
        var ipAddress       = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

        if (string.IsNullOrEmpty(ipAddress))
        {
            ipAddress = context.Request.ServerVariables["REMOTE_ADDR"];
        }
        if (ipAddress.Contains(":") && ipAddress != "::1")
        {
            var parts = ipAddress.Split(':');
            ipAddress = parts[0];
        }
        var    country = GetCountry(ipAddress);
        string userDns;

        try
        {
            userDns = Dns.GetHostEntry(ipAddress).HostName;
        }
        catch
        {
            userDns = "Unknown";
        }
        var pageReferer = context.Request.ServerVariables["HTTP_REFERER"];

        if (string.IsNullOrEmpty(pageReferer))
        {
            pageReferer = "Direct Link";
        }
        using (var db = Database.Open(Functions.GetDbName()))
        {
            const string sqlInsert = "Insert Into Visitors (TimeStamp, Page, Browser, BrowserVersion, OperatingSystem, IPAddress, DNSName, Country, Referer) Values (@0, @1, @2, @3, @4, @5, @6, @7, @8)";
            db.Execute(sqlInsert, timeStamp, page, browser, browserVersion, operatingsystem, ipAddress, userDns, country, pageReferer);
        }
    }