Blog Home  Home Feed your aggregator (RSS 2.0)  
Software Code Help - Wednesday, June 24, 2009
Blog
 
# Wednesday, June 24, 2009

Every .aspx page starts with a Page directive. This Page directive specifies the language for the page,
and it also tells ASP.NET where to find the associated code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FileName.aspx.cs" Inherits="FileName"%>

Notice that Visual Studio uses a slightly unusual naming syntax for the source code file. It has
the full name of the corresponding web page, complete with the .aspx extension, followed by the .cs
extension at the end.

Wednesday, June 24, 2009 12:40:20 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   asp.net  | 

The latest version of Visual Studio has some long-awaited improvements. They include the following:

Web projects: Visual Studio 2005 replaced the traditional project-based web application model with a lighterweight system of projectless development. However, this change didn’t please everyone, and so Microsoft released an add-on that brought the web project option back. In Visual Studio 2008, developers get the best of both worlds, and can choose to create projectless or project-based web applications depending on their needs.

Multitargeting: Web servers won’t shift overnight from .NET 2.0 to .NET 3.5. With this in mind, Visual Studio now gives you the flexibility to develop applications that target any version of the .NET Framework, from version 2.0 on.

CSS: In order to apply consistent formatting over an entire website, developers often use the Cascading Style Sheets (CSS) standard. Now Visual Studio makes it even easier to link web pages to stylesheets, and pick and choose the styles you want to apply to various elements in your page without editing the markup by hand.

Wednesday, June 24, 2009 12:05:21 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   .Net  | 

LINQ and Ajax are the two new features introduced in ASP.NET 3.5

LINQ
-----
LINQ (Language Integrated Query) is a set of extensions for the C# and Visual Basic languages. It allows you to write C# or Visual Basic code that manipulates in-memory data in much the same way you query a database.

Technically, LINQ defines about 40 query operators, such as select, from, in, where, and orderby (in C#). These operators allow you to code your query. However, there are various types of data on which this query can be performed, and each type of data requires a separate flavor  of LINQ.

AJAX
-----
Ajax(Asynchronous JavaScript and XML)is programming shorthand for a client-side technique that allows your page to call the server and update its content without triggering a complete postback. Typically, an Ajax page uses client-side script code to fire an asynchronous request behind the scenes. The server receives this request, runs some code, and then returns the data your page needs (often as a block of XML markup). Finally, the client-side code receives the new data and uses it to perform another action, such as refreshing part of the page.

Green Bits and Red Bits
-------------------------
Oddly enough, ASP.NET 3.5 doesn’t include a full new version of ASP.NET. Instead, ASP.NET 3.5 is designed as a set of features that add on to .NET 2.0. The parts of .NET that haven’t changed in .NET 3.5 are often referred to as red bits, while the parts that have changed are called green bits. The red bits include the CLR, the ASP.NET engine, and all the class libraries from .NET 2.0. In
other words, if you build a new ASP.NET 3.5 application, it gets exactly the same runtime environment as an ASP.NET 2.0 application. Additionally, all the classes you used in .NET 2.0—including those for connecting to a database, reading and writing files, using web controls, and so on—remain the same in .NET 3.5. The red bits also include the features that were included in .NET 3.0, such as WCF. All the assemblies in .NET 3.5 retain their original version numbers. That means .NET 3.5 includes a mix of 2.0, 3.0, and 3.5 assemblies. If you’re curious when an assembly was released, you simply need to check the version number.

The ASP.NET 3.5 green bits consist of a small set of assemblies with new types. For ASP.NET developers, the important new assemblies include the following:

• System.Core.dll: Includes the core LINQ functionality
• System.Data.Linq.dll: Includes the implementation for LINQ to SQL
• System.Data.DataSetExtensions.dll:. Includes the implementation for LINQ to DataSet
• System.Xml.Linq.dll: Includes the implementation for LINQ to XML
• System.Web.Extensions.dll: Includes the implementation for ASP.NET AJAX and new web controls


Silverlight
-----------
Recently, there’s been a lot of excitement about Silverlight, a new Microsoft technology that allows a variety of browsers on a variety of operating systems to run true .NET code. Silverlight works through a browser plug-in, and provides a subset of the .NET Framework class library. This subset includes a slimmed-down version of WPF, the technology that developers use to craft next-generation Windows user interfaces.

Silverlight is all about client code—quite simply, it allows you to create richer pages than you could with HTML, DHTML, and JavaScript alone. In many ways, Silverlight duplicates the features and echoes the goals of Adobe Flash. By using Silverlight in a web page, you can draw sophisticated 2D graphics, animate a scene, and play video and other media files.

Wednesday, June 24, 2009 11:24:55 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   asp.net  | 

There are Four type of symmetric encryption algorithms in .net.

DES 

The Data Encryption Standard (DES) was developed by an IBM team around 1974 and adopted as a national standard in 1977. DES encrypts and decrypts data in 64-bit blocks, using a 64-bit key. Although the input key for DES is 64 bits long, the actual key used by DES is only 56 bits in length. The least significant (right-most) bit in each byte is a parity bit, and should be set so that there are always an odd number of 1s in every byte. These parity bits are ignored, so only the seven most significant bits of each byte are used, resulting in a key length of 56 bits. 

Triple DES 

Triple DES is three times slower than regular DES but can be billions of times more secure if used properly. Triple DES is simply another mode of DES operation. It takes three 64-bit keys, for an overall key length of 192 bits. The procedure for encryption is exactly the same as regular DES, but it is repeated three times, hence the name Triple DES. The data is encrypted with the first key, encrypted with the second key, and finally encrypted again with the third key. Triple DES enjoys much wider use than DES because DES is so easy to break with today's rapidly advancing technology. 

RC2

RC2 (Rivest Cipher) was designed by Ron Rivest as a replacement for DES and boasts a 3 times speed increase over DES. The input and output block sizes are 64 bits each. The key size is variable, from one byte up to 128 bytes, although the current implementation uses eight bytes. The algorithm is designed to be easy to implement on 16-bit microprocessors.

Rijndael

The National Institute of Standards and Technology (NIST) officially announced that Rijndael, designed by Joan Daemen and Vincent Rijmen, would be the new Advanced Encryption Standard.

The Advanced Encryption Standard (AES) is the current encryption standard, intended to be used by  the U.S. Government organisations to protect sensitive (and even secret and top secret) information. It is also becoming a global standard for commercial software and hardware that use encryption. It is a block cipher which uses 128-bit, 192-bit or 256-bit keys. Rijndael is very secure and has no known weaknesses.

Wednesday, June 24, 2009 11:10:15 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   .Net  | 

Some of the differences between ASP.NET and ASP include the following:

• ASP.NET features a completely object-oriented programming model, which includes an event driven,
control-based architecture that encourages code encapsulation and code reuse.

• ASP.NET gives you the ability to code in any supported .NET language (including VisualBasic, C#, J#,
and many other languages that have third-party compilers).

• ASP.NET is dedicated to high performance. ASP.NET pages and components are compiled ondemand
instead of being interpreted every time they’re used. ASP.NET also includes a finetuned
data access
model and flexible data caching to further boost performance.

Wednesday, June 24, 2009 10:46:33 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   asp.net  | 
# Tuesday, June 23, 2009


Java of AES Encryption
=======================
            Cipher encrypt = Cipher.getInstance("AES");
            encrypt.init(Cipher.ENCRYPT_MODE, key);
            byte[] encryptedData = encrypt.doFinal(data);

C# code using Rijndael(AES) 128 Bit encryption
==============================================

 

       ICryptoTransform transform = GetCryptoServiceProvider(SecretKey);

       //Set up the stream that will hold the encrypted data.
       MemoryStream memStreamEncryptedData = GetMemoryStream(transform, bytesData);

        /// <summary>
        /// Create ICryptoTransform object from Rijndael(AES) ECB/PKCS7
        /// </summary>
        /// <param name="bytesKey">Byte Array key</param>
        /// <returns>ICryptoTransform Object</returns>
        private ICryptoTransform GetCryptoServiceProvider(byte[] bytesKey)
        {
            Rijndael rijndael = new RijndaelManaged();
            try
            {
                rijndael.KeySize = 128;
                rijndael.BlockSize = 128;
                rijndael.Mode = CipherMode.ECB;
                rijndael.Padding = PaddingMode.PKCS7;
                // Test to see if a key was provided
                rijndael.GenerateIV();

                if (null != bytesKey)
                {
                    rijndael.Key = bytesKey;
                }
                else
                {
                    rijndael.GenerateKey();
                    SecretKey = rijndael.Key;
                }
            }
            catch (Exception Ex)
            {
                throw new Exception("Error while creating Rijndael(AEs) Object: \n" + Ex.Message);
            }

            return rijndael.CreateEncryptor();

        }

Tuesday, June 23, 2009 12:18:19 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   C#  | 

Java code for retrieve Public key from Certificate
==================================================
 
     KeyStore inputKeyStore = KeyStore.getInstance(Constents.PFX_TYPE);
            FileInputStream fis = new FileInputStream(keyStoreFile);
            char[] nPassword = password.toCharArray();
            inputKeyStore.load(fis, nPassword);
            Enumeration enumeration = inputKeyStore.aliases();
            String keyAlias = null;
            while (enumeration.hasMoreElements()) {
                keyAlias = (String) enumeration.nextElement();
            }
            X509Certificate certificate = (X509Certificate) inputKeyStore
                    .getCertificate(keyAlias);           
            publicKey = certificate.getPublicKey(); 

And Encrypt Code using Public Key of certificate.
=================================================

            Cipher cipher = Cipher.getInstance(xform); //xform:RSA/ECB/PKCS1Padding
            cipher.init(Cipher.ENCRYPT_MODE, publicKey );         
            return cipher.doFinal(Data.getEncoded());


C# compatible Code
===================

Include Namespace of Bouncy Castle Dll.

This DLL is freely available from this link http://www.bouncycastle.org/csharp/

using Org.BouncyCastle.Pkcs;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.X509;
using Org.BouncyCastle.Crypto.Encodings;
using Org.BouncyCastle.Crypto.Engines;

 

               //Create file stream object to read certificate
                FileStream keyStream = new FileStream(strCertificatePath, FileMode.Open, FileAccess.Read);

                //Read certificate using BouncyCastle component
                Pkcs12Store inputKeyStore = new Pkcs12Store(keyStream, strCertificatePassword.ToCharArray());
                
                //Close File stream
                keyStream.Close();

                string keyAlias = null;

                //Read Key from Alieases  
                foreach (string n in inputKeyStore.Aliases)
                {
                    if (inputKeyStore.IsKeyEntry(n))
                    {
                        keyAlias = n;
                        break;
                    }
                }

                if (keyAlias == null)
                    throw new NotImplementedException("Alias");

                //Read certificate into 509 format
                X509Certificate certificate = (X509Certificate)inputKeyStore.GetCertificate(keyAlias).Certificate;

                //Retrieve public key of certificate
                AsymmetricKeyParameter publicKey = certificate.GetPublicKey();
                #endregion

                 //Encrypting (aesKey is a byte array containing an AES key): RSA/ECB/PKCS1Padding
                IAsymmetricBlockCipher cipher = new Pkcs1Encoding(new RsaEngine());
                cipher.Init(true, publicKey);
                byte[] encodedKey = cipher.ProcessBlock(SecretKey, 0, SecretKey.Length);
Tuesday, June 23, 2009 12:10:47 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   C#  | 

First add vjslib.dll from add reference link. Through this dll, we can compress data compatible with Java Compression.

Add Namespace into your class

using java.util.zip;
using java.util;
using java.io;

 

        /// <summary>
        /// This function is used to compress byte array data using java util.
        /// </summary>
        /// <param name="data">Byte Array Data</param>
        /// <param name="path">Path to Store compress File</param>
        /// <param name="fileName">File Name</param>
        public static void compressFileWrite(byte[] data, String path, String fileName)
        {

            try
            {
                java.io.File folder = new java.io.File(path + FORWARD_SLASH + ENCRYPT_OUTPUT_PATH);
                if (!folder.isDirectory())
                {
                    folder.mkdir();
                }
                java.io.File file = new java.io.File(folder.getPath() + FORWARD_SLASH + fileName);
                FileOutputStream fos = new FileOutputStream(file);
                DeflaterOutputStream dos = new DeflaterOutputStream(fos);
                dos.write((sbyte[])(Array)data);
                dos.close();
            }
            catch (java.io.FileNotFoundException Ex)
            {
                throw new Exception("Error while reading file \n" + Ex.Message);
            }
            catch (java.io.IOException Ex)
            {
                throw new Exception("Error in Compress File \n" + Ex.Message);
            }

        }

 This above code is compatible with java compression

Tuesday, June 23, 2009 11:49:36 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   C#  | 
# Monday, June 22, 2009
      Microsoft .net framework provide a facility for sending mail using System.Web.Mail(SMTP)
      First include this using System.Web.Mail in your code, For sending mail we are creating a function sendMail,
      it is used for sending email. For correctly running
      this code, please find register two dll "cdonts.dll" and "cdosys.dll".
      These two dll is microsoft dll used for sending mail.
 
      public void sendMail()
        { 

            try 

            {  

                //Provides properties and methods for sending messages using the Collaboration Data Objects for 
                  Windows 2000 (CDOSYS) message component.
                SmtpMail.SmtpServer= "SMTP Server IP Address";                 MailMessage msg = new MailMessage();                 // Specify the e-mail sender.                 msg.From = "rajshekhar@mail.com";//Self mail address // Set destinations for the e-mail message.                 msg.To = "Send Email Address";                 // Set destinations of Carbon Copy(CC) for the e-mail message.                 msg.Cc = "CC Email Address;                 // Set destinations of Blind carbon copies(BCC) for the e-mail message.                 msg.Bcc = "BCC Email Address";                 // Specify the message subject.                 msg.Subject = this.txtSubject.Text;                 // Specify the message content.                 msg.Body = "Content of Message Assign Here";                 msg.BodyFormat = MailFormat.Text;                 //The username for authenticating to an SMTP server using basic (clear-text) authentication.                 msg.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendusername",
                                 "itq@vmaildeliver.vsnl.com");
                //The password used to authenticate to an SMTP server using basic (clear-text) authentication.                 msg.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendpassword","itq.1.123");                 /%                         Specifies the authentication mechanism to use when authentication is required to send messages
                to an SMTP service using a TCP/IP network socket.                                                          The Secound parameter in smtpauthenticateis CdoProtocolsAuthentication enumeration, It is
                used to specify the mechanism used when authenticating to a Simple Mail Transfer Protocol(SMTP)
                service over the network.                 It has three different type of value:                 Name            Value                Description                 ====            =====                ============                 cdoAnonymous     0                 Do not authenticate.                                  cdoBasic         1                 Use basic (clear-text) authentication. The configuration
                                                   sendusername/sendpassword or postusername/postpassword fields
                                                  are used to specify credentials.                                  cdoNTLM             2              Use NTLM authentication (Secure Password Authentication in
                                                   Microsoft® Outlook® Express).The current process security
                                                   context is used to authenticate with the service.                                  */                                             msg.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",1);                 //Sending Message                             SmtpMail.Send(msg);                              }             catch (Exception ex)             {                 ErrorMessage("Send Mail Process was failed!!!");                              }             finally             {                                  SuccessMessage("Send Mail Process was successfull!!!");             }         }

You can use this above code for sending mail using SMTP in ASP.NET.

Monday, June 22, 2009 11:26:30 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   .Net | asp.net  | 
# Sunday, June 21, 2009

In SQL Server 2000,


sp_lock is used to find dead lock inside the database.
if any dead lock occur then using "Kill spid" is to remove the dead lock.

Sunday, June 21, 2009 11:39:11 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   SQL Server  | 
Copyright © 2010 SoftwareCodeHelp. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.
Pick a theme: