Blog Home  Home Feed your aggregator (RSS 2.0)  
Software Code Help - Monday, June 29, 2009
Blog
 
# Monday, June 29, 2009
In ASP.NET 2.0, managing controls has become easier. Instead of declaring them on every page, you can declare them only once in your web.config file and use them in your entire project.
<configuration>
    <system.web>       
      <pages>
            <controls>
                  <add tagPrefix="portal" tagName="Top"src="~/Controls/Top.ascx" />
            </controls >
      </pages >  
    </system.web>
</configuration>
Once you have registered this control in your web.config, you can use this control on any page without explicitly adding a register directive on the page.
<body>
    <form id="form1" runat="server">
    <div>
        <portal:Top ID="Top1" runat="server" />
    </div>
    </form>
</body>
 
Monday, June 29, 2009 10:03:00 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   asp.net  | 
# Friday, June 26, 2009

One difference is that web forms start with the Page directive, a master page starts with a Master directive that specifies the same information, as shown here:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="SiteTemplate.master.cs" Inherits="SiteTemplate" %>

Another difference between master pages and ordinary web forms is that master pages can use the ContentPlaceHolder control, which isn’t allowed in ordinary pages. The ContentPlaceHolder is a portion of the page where the content page can insert content.

Friday, June 26, 2009 12:47:09 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   asp.net  | 
# 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#  | 
Copyright © 2010 SoftwareCodeHelp. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.
Pick a theme: