MasterPage


For example, you might have a master page named MasterPage.master that is the class name MasterPage_master. You might create @ Page and @ MasterType directives that look like the following:
<%@ Page  masterPageFile="~/MasterPage.master"%>
<%@ MasterType  virtualPath="~/MasterPage.master"%>
When you use a @ MasterType directive, such as the one in the example, you can reference members on the master page as in the following example:

EncryptRJ256

 public string UpdateLeaderBoard(string pname, string fscore, string ipaddress, string gameid)
        {
            string timestamp = DateTime.Now.ToShortTimeString();
            lboardparameters = fscore + "," + timestamp + "," + ipaddress + "," + gameid;
            string sKy = "go!Animate@2010Cart00nNetw@rk!!!";

            string sIV = "go!Animate@2010Cart00nNetw@rk!!!";


            lboardparameters = EncryptRJ256(sKy, sIV, lboardparameters);
            // string url = "http://www.cartoonnetworkasia.com/contest/2010/09_hp_smart_numbers_up/gameSubmit.php?lboardparameters=" + lboardparameters;
            return lboardparameters;
            //openurl();
        }

        public static string EncryptRJ256(string prm_key, string prm_iv, string prm_text_to_encrypt)
        {

            string sToEncrypt = prm_text_to_encrypt;

            RijndaelManaged myRijndael = new RijndaelManaged();
            myRijndael.Padding = PaddingMode.Zeros;
            myRijndael.Mode = CipherMode.CBC;
            myRijndael.KeySize = 256;
            myRijndael.BlockSize = 256;

            byte[] encrypted = null;
            byte[] toEncrypt = null;
            byte[] key = null;
            byte[] IV = null;

            key = System.Text.Encoding.ASCII.GetBytes(prm_key);
            IV = System.Text.Encoding.ASCII.GetBytes(prm_iv);

            ICryptoTransform encryptor = myRijndael.CreateEncryptor(key, IV);

            MemoryStream msEncrypt = new MemoryStream();
            CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write);

            toEncrypt = System.Text.Encoding.ASCII.GetBytes(sToEncrypt);

            csEncrypt.Write(toEncrypt, 0, toEncrypt.Length);
            csEncrypt.FlushFinalBlock();

            encrypted = msEncrypt.ToArray();

            return (Convert.ToBase64String(encrypted));

        }

Encryption and decryption in SHA1Managed

private string Encrypt(string Data)
{
 SHA1Managed shaM = new SHA1Managed();
 Convert.ToBase64String(shaM.ComputeHash(Encoding.ASCII.GetBytes(Data)));
 byte[] eNC_data = ASCIIEncoding.ASCII.GetBytes(Data);
 string eNC_str = Convert.ToBase64String(eNC_data);
 return eNC_str;
}
//Encrypt

private string Decrypt(string Data)
{
 byte[] dEC_data = Convert.FromBase64String(Data);
 string dEC_Str = ASCIIEncoding.ASCII.GetString(dEC_data);
 return dEC_Str;
}
//Decrypt
 
 
 
 
 

C# SHA-2 Cryptography: SHA-256, SHA-384, SHA-512

Here are some crypto methods for SHA256, SHA384, and SHA512 which I had not posted about before. This is the class I am using.

using System.Security.Cryptography;
using System.Text;

public class clsCrypto {
public clsCrypto() {
}
public static string md5encrypt(string phrase) {
UTF8Encoding encoder = new UTF8Encoding();
MD5CryptoServiceProvider md5hasher = new MD5CryptoServiceProvider();
byte[] hashedDataBytes = md5hasher.ComputeHash(encoder.GetBytes(phrase));
return byteArrayToString(hashedDataBytes);
}
public static string sha1encrypt(string phrase) {
UTF8Encoding encoder = new UTF8Encoding();
SHA1CryptoServiceProvider sha1hasher = new SHA1CryptoServiceProvider();
byte[] hashedDataBytes = sha1hasher.ComputeHash(encoder.GetBytes(phrase));
return byteArrayToString(hashedDataBytes);
}
public static string sha256encrypt(string phrase) {
UTF8Encoding encoder = new UTF8Encoding();
SHA256Managed sha256hasher = new SHA256Managed();
byte[] hashedDataBytes = sha256hasher.ComputeHash(encoder.GetBytes(phrase));
return byteArrayToString(hashedDataBytes);
}
public static string sha384encrypt(string phrase) {
UTF8Encoding encoder = new UTF8Encoding();
SHA384Managed sha384hasher = new SHA384Managed();
byte[] hashedDataBytes = sha384hasher.ComputeHash(encoder.GetBytes(phrase));
return byteArrayToString(hashedDataBytes);
}
public static string sha512encrypt(string phrase) {
UTF8Encoding encoder = new UTF8Encoding();
SHA512Managed sha512hasher = new SHA512Managed();
byte[] hashedDataBytes = sha512hasher.ComputeHash(encoder.GetBytes(phrase));
return byteArrayToString(hashedDataBytes);
}
public static string byteArrayToString(byte[] inputArray) {
StringBuilder output = new StringBuilder("");
for (int i = 0; i < inputArray.Length; i++) {
output.Append(inputArray[i].ToString("X2"));
}
return output.ToString();
}
}
 

Difference between managed code and unmanaged code

Managed Code:
Code that runs under a "contract of cooperation" with the common language runtime. Managed code must supply the metadata necessary for the runtime to provide services such as memory management, cross-language integration, code access security, and
automatic lifetime control of objects. All code based on Microsoft intermediate language (MSIL) executes as managed code.

Un-Managed Code:
Code that is created without regard for the conventions and requirements of the common language runtime. Unmanaged code executes in the common language runtime environment with minimal services (for example, no garbage collection, limited debugging, and so on).


Managed Code:-
Managed code is code written in one of over twenty high-level programming languages that are available for use with the Microsoft® .NET Framework, including C#, J#, Microsoft Visual Basic® .NET, Microsoft JScript® .NET, and C++. All of these languages share a unified set of class libraries and can be encoded into an Intermediate Language (IL). A runtime-aware compiler compiles the IL into native executable code within a managed execution environment that ensures type safety, array bound and index checking, exception handling, and garbage collection.

By using managed code and compiling in this managed execution environment, you can avoid many typical programming mistakes that lead to security holes and unstable applications. Also, many unproductive programming tasks are automatically taken care of, such as type safety checking, memory management, and destruction of unneeded objects. You can therefore focus on the business logic of your applications and write them using fewer lines of code. The result is shorter development time and more secure and stable applications.

UnManaged Code
The Microsoft .NET Framework promotes interaction with COM components, COM+ services, external type libraries, and many operating system services. Data types, method signatures, and error-handling mechanisms vary between managed and unmanaged object models. To simplify interoperation between .NET Framework components and unmanaged code and to ease the migration path, the common language runtime conceals from both clients and servers the differences in these object models.

Code executing under the control of the runtime is called managed code. Conversely, code that runs outside the runtime is called unmanaged code. COM components, ActiveX interfaces, and Win32 API functions are examples of unmanaged code.



difference between custom control and user control

User control

1) Reusability web page
2) We can’t add to toolbox
3) Just drag and drop from solution explorer to page (aspx)
4) U can register user control to. Aspx page by Register tag
5) A separate copy of the control is required in each application
6) Good for static layout
7) Easier to create
8)Not complied into DLL
9) Here page (user page) can be converted as control then
We can use as control in aspx

Custom controls

1) Reusability of control (or extend functionalities of existing control)
2) We can add toolbox
3) Just drag and drop from toolbox
4) U can register user control to. Aspx page by Register tag
5) A single copy of the control is required in each application
6) Good for dynamics layout
7) Hard to create
8) Compiled in to dll
  
When to use?

Good question: "When to use a Custom Control?" Haven't you got the inner meaning of it yet? OK, read the summarized points below:
  • When you have a rapid and fixed content in your UI, use UserControl.
  • When you want to separate some basic functionality of your main view to some smaller pieces with reusability, use UserControl.
  • When you want to use your control in different projects and each project may want to change the look, use CustomControl.
  • When you want to implement some additional functionality for a control, create a CustomControl derived from the base control.
  • When you want to apply themes to your controls, use CustomControl.
  • When you want to add toolbox support for your control, so that your user will be able to do drag and drop to the designer, use CustomControl.