Wednesday, May 28, 2008

How to create DLL for .NET 2.0 Web Application

How to create DLL for .NET 2.0 Web Application

If you have layers structure in .NET solution and when you build the solution, visual studio creates DLLs for business layer and data access layer, but visual studio not creates DLL for presentation or UI layer.

You will face issue to run Microsoft FxCop tool for Presentation layer. To run FxCop tool you needs dll or exe. You can create dll for presentation layer using VS 2005, follow the steps below

1) Create a new folder on C drive, like: C:\Temp\ProjectDeploy

2) Open the project in the Visual studion 2005

3) Go to the project right click and choose “Publish Web site” option

4) Give “C:\Temp\ProjectDeploy” in the Target Location and click “OK”

5) You will see your presentation layer dlls inside the ProjectDeploy\bin folder

Note: Fxcop Tool can be integrate with visual studio 2005 see more details here

Tuesday, May 13, 2008

PROGRAMATICALLY CONFIGURATION FILES ENCRYPTION AND DECRYPTION USING C#.NET

PROGRAMATICALLY CONFIGURATION FILES ENCRYPTION AND DECRYPTION USING C#.NET

In .Net application (web/window) configuration file we used to make application setting as configurable. Each and every time you need not to compile your project for any setting changes in the configuration file. This configuration file present in virtual directory of the application. When you deploy the application, it can be editable by the users who have all permission for that deployment server and one server can have several applications, this time it is necessary to keep your application configuration file secure or use encrypted configuration file to secure your application setting data.

Previously we used to write encryption decryption function using different .Net notation (like: SHA, MD5 etc) and manually updating configuration file. Here I am giving new way to do same task programmatically, you can do encrypt or decrypt any project configuration file appSettings or connectionStrings sections programmatically

ASP.NET 2.0 and above makes it extremely easy to encrypt connection strings, encrypt application settings, and encrypt config sections in Web.config either via the command prompt with aspnet_regiis or programmatically in your web applications.

Source Code:

Create application to encrypt or decrypt configuration file using C#/VB.Net windows or web application.

Here I am creating window application using C#.net, Follow the simple four steps to create application.

1) app.config file sections Before Encryption

For example:

<appSettings>

<add key="ServerName" value="Your Machine Name" />

<add key="Password" value="123.456.78" />

</appSettings>

2) app.config file sections After Encryption

For example:

<appSettings configProtectionProvider="DataProtectionConfigurationProvider">

<EncryptedData>

<CipherData>

<CipherValue>MSDFSDFGSSD$SFSD%VAAAAAAGDFGDFGGGGGGGVBCXBVBVCBBVCVBVCBBBTYRTYRTY%UUUUUUUU</CipherValue>

</CipherData>

</EncryptedData>

</appSettings>

2) You can design your window form something like below

3) Code for Encrypt and Decrypt button

NameSpace

using System.Web.Configuration;

Call following function from Encrypt button code behind

Function for Encryption

private int EncryptConfigurationSection(string fileName, string sectionName, string provider)

{

//Creates a FileMap Object to store the File Name of Configuration File

ExeConfigurationFileMap FileMap = new ExeConfigurationFileMap();

//Assigning the File Name to the File Map

FileMap.ExeConfigFilename = fileName;

//Retrieving the Configuration from the File Provided

Configuration config =

ConfigurationManager.OpenMappedExeConfiguration(FileMap, ConfigurationUserLevel.None);

//Checking if the File Provided is a Configuration File Or Not

if (config.HasFile) {

//Retrieve the Section from the Configuration Object

ConfigurationSection section = config.GetSection(sectionName);

//Check if the Section is not null or is not Previously Protected

if (section != null && !section.SectionInformation.IsProtected) {

//Provide Protection to the Section as per the provider

section.SectionInformation.ProtectSection(provider);

//Save the Configuration object and the File

config.Save();

return 1;

}

else{

if (section != null) {return 3;}

else {return 0;}

}

}

else {return 2;}

}

Function for De-Encryption

Call following function from Dncrypt button code behind

private int DncryptConfigurationSection(string fileName, string sectionName)

{

//Creates a FileMap Object to store the File Name of Configuration File

ExeConfigurationFileMap FileMap = new ExeConfigurationFileMap();

//Assigning the File Name to the File Map

FileMap.ExeConfigFilename = fileName;

//Retrieving the Configuration from the File Provided

Configuration config =

ConfigurationManager.OpenMappedExeConfiguration(FileMap, ConfigurationUserLevel.None);

//Checking if the File Provided is a Configuration File Or Not

if (config.HasFile) {

//Retrieve the Section from the Configuration Object

ConfigurationSection section = config.GetSection(sectionName);

//Check if the Section is not null or is not Previously Protected

if (section != null && section.SectionInformation.IsProtected) {

//Remove the Protection from the Section

section.SectionInformation.UnprotectSection();

//Save the Configuration Object and the File

config.Save();

return 1;

}

else {

if (section != null) {return 3;}

else {return 0;}

}

} else {return 2;}

}

Note:

In the above functions 0 to 3 used for

0 --> Wrong Section as per Configuration file

1 --> Successful Encyprtion/Decryption Information

2 --> Wrong Configuration File name

3 --> Configuration section in file is not encrypted

H/W Platform: Dual Processor with 1 GB RAM

S/W Environment: ASP.NET, VB.NET and C#.NET

Wednesday, April 16, 2008

Most frequently used short cuts in window XP

Most frequently used short cuts in window XP

To Access….

Run Command

Wordpad

Write

SQL server 2005

sqlwb

Visual Studio 2005

devenv

Internet Information server

inetmgr

IIS re-start

iisreset

Windows Explorer

explorer

Add/Remove Programs

appwiz.cpl

Administrative Tools

control admintools

Adobe Acrobat (if installed)

acrobat

Adobe Photoshop (if installed)

photoshop

Calculator

Calc

Check Disk Utility

Chkdsk

Command Prompt

Cmd

Control Panel

control

Disk Defragment

dfrg.msc

Event Viewer

eventvwr.msc

Internet Explorer

iexplore

Internet Properties

inetcpl.cpl

Logs You Out Of Windows

Logoff

Microsoft Word (if installed)

winword

Microsoft Excel (if installed)

excel

Notepad

Notepad

Net Meeting

conf

Microsoft Paint

mspaint

Performance Monitor

perfmon.msc

Windows Media Player

wmplayer

Task Manager

Taskmgr

Remote Desktop

Mstsc

Registry Editor

regedit

Registry Editor

regedit32

Shuts Down Windows

Shutdown

Some more short cuts

To Access….

Run Command

Accessibility Controls

access.cpl

Accessibility Wizard

accwiz

Add Hardware Wizard

hdwwiz.cpl

Adobe Designer (if installed)

acrodist

Adobe Distiller (if installed)

acrodist

Adobe ImageReady (if installed)

imageready

Automatic Updates

wuaucpl.cpl

Bluetooth Transfer Wizard

fsquirt

Certificate Manager

certmgr.msc

Character Map

charmap

Clipboard Viewer

clipbrd

Component Services

dcomcnfg

Computer Management

compmgmt.msc

Control Panel

control

Date and Time Properties

timedate.cpl

DDE Shares

ddeshare

Device Manager

devmgmt.msc

Direct X Control Panel (If Installed)*

directx.cpl

Direct X Troubleshooter

dxdiag

Disk Cleanup Utility

cleanmgr

Disk Management

diskmgmt.msc

Disk Partition Manager

diskpart

Display Properties

control desktop

Display Properties

desk.cpl

Display Properties (w/Appearance Tab Preselected)

control color

Dr. Watson System Troubleshooting Utility

drwtsn32

Driver Verifier Utility

verifier

Files and Settings Transfer Tool

migwiz

File Signature Verification Tool

sigverif

Findfast

findfast.cpl

Firefox (if installed)

firefox

Folders Properties

control folders

Fonts

control fonts

Fonts Folder

fonts

Free Cell Card Game

freecell

Game Controllers

joy.cpl

Group Policy Editor (XP Prof)

gpedit.msc

Hearts Card Game

mshearts

Help and Support

helpctr

HyperTerminal

hypertrm

Iexpress Wizard

iexpress

Indexing Service

ciadv.msc

Internet Connection Wizard

icwconn1

Internet Setup Wizard

inetwiz

IP Configuration (Display Connection Configuration)

ipconfig /all

IP Configuration (Display DNS Cache Contents)

ipconfig /displaydns

IP Configuration (Delete DNS Cache Contents)

ipconfig /flushdns

IP Configuration (Release All Connections)

ipconfig /release

IP Configuration (Renew All Connections)

ipconfig /renew

IP Configuration (Refreshes DHCP & Re-Registers DNS)

ipconfig /registerdns

IP Configuration (Display DHCP Class ID)

ipconfig /showclassid

IP Configuration (Modifies DHCP Class ID)

ipconfig /setclassid

Java Control Panel (If Installed)

jpicpl32.cpl

Java Control Panel (If Installed)

javaws

Keyboard Properties

control keyboard

Local Security Settings

secpol.msc

Local Users and Groups

lusrmgr.msc

Malicious Software Removal Tool

mrt

Microsoft Access (if installed)

access.cpl

Microsoft Chat

winchat

Microsoft Frontpage (if installed)

frontpg

Microsoft Movie Maker

moviemk

Microsoft Powerpoint (if installed)

powerpnt

Microsoft Syncronization Tool

mobsync

Minesweeper Game

winmine

Mouse Properties

control mouse

Mouse Properties

main.cpl

Nero (if installed)

nero

Network Connections

control netconnections

Network Connections

ncpa.cpl

Network Setup Wizard

netsetup.cpl

Nview Desktop Manager (If Installed)

nvtuicpl.cpl

Object Packager

packager

ODBC Data Source Administrator

odbccp32.cpl

On Screen Keyboard

osk

Opens AC3 Filter (If Installed)

ac3filter.cpl

Outlook Express

msimn

Password Properties

password.cpl

Performance Monitor

perfmon

Phone and Modem Options

telephon.cpl

Phone Dialer

dialer

Pinball Game

pinball

Power Configuration

powercfg.cpl

Printers and Faxes

control printers

Printers Folder

printers

Private Character Editor

eudcedit

Quicktime (If Installed)

QuickTime.cpl

Quicktime Player (if installed)

quicktimeplayer

Real Player (if installed)

realplay

Regional Settings

intl.cpl

Remote Access Phonebook

rasphone

Removable Storage

ntmsmgr.msc

Removable Storage Operator Requests

ntmsoprq.msc

Resultant Set of Policy (XP Prof)

rsop.msc

Scanners and Cameras

sticpl.cpl

Scheduled Tasks

control schedtasks

Security Center

wscui.cpl

Services

services.msc

Shared Folders

fsmgmt.msc

Sounds and Audio

mmsys.cpl

Spider Solitare Card Game

spider

SQL Client Configuration

cliconfg

System Configuration Editor

sysedit

System Configuration Utility

msconfig

System File Checker Utility (Scan Immediately)

sfc /scannow

System File Checker Utility (Scan Once At Next Boot)

sfc /scanonce

System File Checker Utility (Scan On Every Boot)

sfc /scanboot

System File Checker Utility (Return to Default Setting)

sfc /revert

System File Checker Utility (Purge File Cache)

sfc /purgecache

System File Checker Utility (Set Cache Size to size x)

sfc /cachesize=x

System Information

msinfo32

System Properties

sysdm.cpl

TCP Tester

tcptest

Telnet Client

telnet

Tweak UI (if installed)

tweakui

User Account Management

nusrmgr.cpl

Utility Manager

utilman

Windows Address Book

wab

Windows Address Book Import Utility

wabmig

Windows Backup Utility (if installed)

ntbackup

Windows Firewall

firewall.cpl

Windows Magnifier

magnify

Windows Management Infrastructure

wmimgmt.msc

Windows Messenger

msmsgs

Windows Picture Import Wizard (need camera connected)

wiaacmgr

Windows System Security Tool

syskey

Windows Update Launches

wupdmgr

Windows Version (to show which version of windows)

winver

Windows XP Tour Wizard

tourstart