Monday, 13 May 2013

JQuery Html Editor

http://premiumsoftware.net/cleditor/


$("#txtEditor").cleditor({ sizes:        // sizes in the font size popup
                        "1,2,3,4,5,6,7,8"
    });

Sunday, 12 May 2013

Setting for set max json string length in web config

Use this Json sting setting in web.config file.

<system.web.extensions>
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength="999999999">
        </jsonSerialization>
      </webServices>
    </scripting>
  </system.web.extensions>

Rewrite url setting in web.config


<system.webServer>
    <rewrite>
      <rules>
        <rule name="Redirect to WWW"  enabled="true" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^(domainname).(com)$" />
          </conditions>
          <action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}"
               redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
</system.webServer>

Get city,state,country from ip address in asp.net c# service



IpAddress = HttpContext.Current.Request.UserHostAddress.ToString();
                List<LocationbyIp> l = (GetGeoLocation(IpAddress));



private static List<LocationbyIp> GetGeoLocation(string ipaddress)
    {

        string APIKey = "7ecaaa8486a31ae8ac36a09c84ffc4c2783552766804c8f351b1f43dc096b26f";
        string url = string.Format("http://api.ipinfodb.com/v3/ip-city/?key={0}&ip={1}&format=json", APIKey, ipaddress);
        using (WebClient client = new WebClient())
        {
            string json = client.DownloadString(url);
            LocationbyIp location = new JavaScriptSerializer().Deserialize<LocationbyIp>(json);
            List<LocationbyIp> locations = new List<LocationbyIp>();
            locations.Add(location);
            return locations;

        }
    }
///////////////// Entity ///////

public class LocationbyIp
{

    public string IPAddress { get; set; }
    public string CountryName { get; set; }
    public string CountryCode { get; set; }
    public string CityName { get; set; }
    public string RegionName { get; set; }
    public string ZipCode { get; set; }
    public string Latitude { get; set; }
    public string Longitude { get; set; }
    public string TimeZone { get; set; }
public LocationbyIp()
{
//
// TODO: Add constructor logic here
//
}
}

Monday, 22 April 2013

Get querystring in javascript


function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.search);
    if (results == null)
        return "";
    else
        return decodeURIComponent(results[1].replace(/\+/g, " "));
}

set and get cookies in javascript/C#

Using Javascript

function setCookie(c_name, value, exdays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
    document.cookie = c_name + "=" + c_value + "; path=/";

}

/*Get Cookie Value */
function getCookie(c_name) {
    var i, x, y, ARRcookies = document.cookie.split(";");
    for (i = 0; i < ARRcookies.length; i++) {
        x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
        y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
        x = x.replace(/^\s+|\s+$/g, "");
        if (x == c_name) {
            return unescape(y);
        }
    }
}

From .cs file

HttpCookie oCookie = (HttpCookie)HttpContext.Current.Request.Cookies["Cookiename"];
oCookie.Expires = DateTime.Now.AddHours(4);
oCookie.Value="123";
HttpContext.Current.Response.Cookies.Add(oCookie);

check browser in jquery


navigator.sayswho = (function () {
    var N = navigator.appName,
        ua = navigator.userAgent,
        tem;
    var M = ua.match(/(opera|chrome|safari|firefox|msie)\/?\s*(\.?\d+(\.\d+)*)/i);
    if (M && (tem = ua.match(/version\/([\.\d]+)/i)) != null) M[2] = tem[1];
    M = M ? [M[1], M[2]] : [N, navigator.appVersion, '-?'];
    return M;
})();