Monday, 21 April 2014

RSS news

http://www.jquery-plugins.net/FeedEK/FeedEk_demo.html

http://www.jquery-plugins.net/FeedEK/FeedEK.html

https://github.com/enginkizil/FeedEk

Friday, 18 April 2014

Find Block url status using C#

private bool isValidURL(string url)
    {
        WebRequest webRequest = WebRequest.Create(url);
        WebResponse webResponse;
        try
        {
            webResponse = webRequest.GetResponse();
        }
        catch //If exception thrown then couldn't get response from address
        {
            return false;
        }
        return true;
    }

Thursday, 17 April 2014

Encrypt and Decrypt password using C#

using System.Security.Cryptography;


 private string Encrypt(string clearText)
    {
        string strmsg = string.Empty;
        byte[] encode = new byte[clearText.Length];
        encode = Encoding.UTF8.GetBytes(clearText);
        strmsg = Convert.ToBase64String(encode);
        return strmsg;
    }

    private string Decrypt(string cipherText)
    {
        string decryptpwd = string.Empty;
        UTF8Encoding encodepwd = new UTF8Encoding();
        Decoder Decode = encodepwd.GetDecoder();
        byte[] todecode_byte = Convert.FromBase64String(cipherText);
        int charCount = Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
        char[] decoded_char = new char[charCount];
        Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
        decryptpwd = new String(decoded_char);
        return decryptpwd;
    }

Decrypt and Encrypt password using asp .net C#

using System.Security.Cryptography;
/*-----------------------------------------------*/

private string Encrypt(string clearText)
    {
        string EncryptionKey = "MAKV2SPBNI99212";
        byte[] clearBytes = Encoding.Unicode.GetBytes(clearText);
        using (Aes encryptor = Aes.Create())
        {
            Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
            encryptor.Key = pdb.GetBytes(32);
            encryptor.IV = pdb.GetBytes(16);
            using (MemoryStream ms = new MemoryStream())
            {
                using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write))
                {
                    cs.Write(clearBytes, 0, clearBytes.Length);
                    cs.Close();
                }
                clearText = Convert.ToBase64String(ms.ToArray());
            }
        }
        return clearText;
    }
/*-----------------------------------------------------------------------------------------*/
    private string Decrypt(string cipherText)
    {
        string EncryptionKey = "MAKV2SPBNI99212";
        byte[] cipherBytes = Convert.FromBase64String(cipherText);
        using (Aes encryptor = Aes.Create())
        {
            Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
            encryptor.Key = pdb.GetBytes(32);
            encryptor.IV = pdb.GetBytes(16);
            using (MemoryStream ms = new MemoryStream())
            {
                using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write))
                {
                    cs.Write(cipherBytes, 0, cipherBytes.Length);
                    cs.Close();
                }
                cipherText = Encoding.Unicode.GetString(ms.ToArray());
            }
        }
        return cipherText;
    }

Wednesday, 16 April 2014

JQuery Slider

http://www.jssor.com/demos/x-fly.html

In C# Code Behind Validate Valid user or not using basepage

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

/// <summary>
/// Summary description for BasePage
/// </summary>

public class BasePage : System.Web.UI.Page
{
    protected override void OnPreInit(EventArgs e)
    {
        string cTheFile = HttpContext.Current.Request.Path;

        // here select what part of that string you won to check out
        if (!GetAuthenticatedRolesByModuleName(cTheFile))
        {
            // some how avoid the crash if call the same page again
            if (!cTheFile.EndsWith("Default.aspx"))
            {
                Response.Redirect("Default.aspx", true);
                return;
            }
        }

        // continue with the rest of the page
        base.OnPreInit(e);
    }

    private bool GetAuthenticatedRolesByModuleName(string cTheFile)
    {
        if (Session["Name"]!=null)
        {
            return true;
        }
        else
        {

            return false;
        }
    }
}

Wednesday, 9 April 2014

send mail using C#

 {
        string status = "";
        try
        {
            if (!string.IsNullOrEmpty(ToEmail))
            {
                ToEmail = ConfigurationManager.AppSettings["toMailId"].ToString();
            }
            string MailSenderEmail = ConfigurationManager.AppSettings["SenderEmail"].ToString();
            string MailSenderPwd = ConfigurationManager.AppSettings["SenderPwd"].ToString();
            string smtpInfo = ConfigurationManager.AppSettings["smtpInfo"].ToString();
            string Port = ConfigurationManager.AppSettings["Port"].ToString();

            MailMessage mail = new MailMessage();
            mail.Subject = subj;
            mail.From = new MailAddress(MailSenderEmail);
            mail.To.Add(ToEmail);
            mail.Body = bodymsg;
            mail.IsBodyHtml = true;

            SmtpClient smtp = new SmtpClient(smtpInfo, Util.ToInt32(Port));
            smtp.EnableSsl = true;
            NetworkCredential netCre = new NetworkCredential(MailSenderEmail, MailSenderPwd);
            smtp.Credentials = netCre;
            smtp.Send(mail);
            status = "1";
        }
        catch (Exception e)
        {
            e.Message.ToString();
            status = e.Message.ToString();
        }
        return status;
    }