Monday, December 22, 2008

Adding/Updating/Deleting Rows in SQL Server 2005 Management Studio

I had been having problems with regards to adding or updating rows from the management studio with my version of SQL Server on the dev server, but it worked perfect on the live server. I use to write add and update queries to update my records, but this is a hassle if I would like to update large number of rows. So I wanted a quick solution to this. On doing some R & D, I found out that the "no count" feature which is available in the "SQL Server" properties (obtained by right clicking on the Registered Server and clicking on properties).



You can find the "no count" property in the "Connections" tab under "Default connection options". Just uncheking the "no count" feature and refreshing your server would make it work. Voila !!!

Friday, November 14, 2008

Power Commands for Visual Studio 2008

Hello Guys,

This, being my first post, I want to make a powerful debut. Though the content is not produced by me (Ya its the microsoft guys), I hope it will be useful for using them. Shower your power !!!


What’s New in PowerCommands 1.1

Enable/Disable PowerCommands in Options dialog

This feature allows you to select which commands to enable in the Visual Studio IDE. Point to the Tools menu, then click Options. Expand the PowerCommands options, then click Commands. Check the commands you would like to enable.

Format document on save / Remove and Sort Usings on save

The Format document on save option formats the tabs, spaces, and so on of the document being saved. It is equivalent to pointing to the Edit menu, clicking Advanced, and then clicking Format Document.

The Remove and sort usings option removes unused using statements and sorts the remaining using statements in the document being saved.

Note: The Remove and sort usings option is only available for C# documents.

Note: Format document on save and Remove and sort usings both are initially defaulted OFF.

To select either option, point to the Tools menu, then click Options. Expand the PowerCommands options, and then click General.

Note: If you click Save, the option you select applies to the selected document. If you click Save All, the option applies to all open documents.

Clear All Panes

This command clears all output panes. It can be executed from the button on the toolbar of the Output window.

Copy Path

This command copies the full path of the currently selected item to the clipboard. It can be executed by right-clicking one of these nodes in the Solution Explorer:

· The solution node.

· A project node.

· Any project item node.

· Any folder.

Email CodeSnippet

To email the lines of text you select in the code editor, right-click anywhere in the editor and then click Email CodeSnippet.

Note: If no lines are selected, the entire document will be emailed.

Insert Guid Attribute

This command adds a Guid attribute to a selected class. From the code editor, right-click anywhere within the class definition, then click Insert Guid Attribute.

Note: If the class already has a Guid attribute, the Insert Guid Attribute command will not be visible.

Show All Files

This command shows the hidden files in all projects displayed in the Solution Explorer when the solution node is selected. It enhances the Show All Files button, which normally shows only the hidden files in the selected project node.

Undo Close

This command reopens a closed document , returning the cursor to its last position. To reopen the most recently closed document, point to the Edit menu, then click Undo Close. Alternately, you can use the Ctrl+Shift+Z shortcut.

To reopen any other recently closed document, point to the View menu, click Other Windows, and then click Undo Close Window. The Undo Close window appears, typically next to the Output window.

Double-click any document in the list to reopen it.

What’s New in PowerCommands 1.0

Collapse Projects

This command collapses a hierarchy in the solution explorer starting from the root selected node. It can be executed from three different places: solution, solution folders and project nodes respectively.

Copy Class

This command copies a selected class entire content to the clipboard. It can be executed from a single project item or a project item with dependent sub items.

Paste Class

This command pastes a class entire content from the clipboard. It can be executed from a project or folder node.

Copy References

This command copies a reference or set of references to the clipboard. It can be executed from the references node, a single reference node or set of reference nodes.


Paste References

This command pastes a reference or set of references from the clipboard. It can be executed from different places depending on the type of project. For CSharp projects it can be executed from the references node. For Visual Basic and Website projects it can be executed from the project node.

Copy As Project Reference

This command copies a project as a project reference to the clipboard. It can be executed from a project node.

Edit Project File

This command opens the MSBuild project file for a selected project inside Visual Studio. It can be executed from a project node.

Open Containing Folder

This command opens a Windows Explorer window pointing to the physical path of a selected item. It can be executed from a project item node

Open Command Prompt

This command opens a Visual Studio command prompt pointing to the physical path of a selected item. It can be executed from four different places: solution, project, folder and project item nodes respectively.

Unload Projects

This command unloads all projects in a solution. It can be executed from the solution node.

Reload Projects

This command reloads all unloaded projects in a solution. It can be executed from the solution node.

Remove and Sort Usings

This command removes and sort using statements for all classes given a project. It can be executed from a solution node or a single project node.

Note: The Remove and Sort Usings feature is only available for C# projects since the C# editor implements this feature as a command in the C# editor (which this command calls for each .cs file in the project).

Extract Constant

This command creates a constant definition statement for a selected text. It can be executed from the code window over a selected text.

After specifying the constant visibility and identifier (Figure 24) the following constant declaration is created:

Clear Recent File List

This command clears the Visual Studio recent file list.

Clear Recent Project List

This command clears the Visual Studio recent project list.

Transform Templates

This command executes the associated custom tool with text templates items. It can be executed from a DSL project node or a folder node.

Close All

This command closes all documents. It can be executed from a document tab.


Here's link to the PowerCommands download page

Sunday, June 29, 2008

Retreive Windows Stored Passwords

One thing that everyone must have experienced is to remove the stored user credentials on a Windows PC, when you start to think it can become a security vulnerability. I did little googling on this, after failing to find out where those passwords were stored. I wanted to remove my remote server's stored credentials. The search result showed a cute windows command to be entered to get there. Cute! I love windows command shortcuts!

Here's what it is:

Type the following command in the Run window (Windows + R):

rundll32.exe keymgr.dll, KRShowKeyMgr

This will take you to the Password management store.


Thats it! You can do whatever you want from here. Needs no further explaination

Friday, June 22, 2007

Digital signing of code for unsigned components

Hello guys,

This article of mine explains how to sign a code without the need to buy the digital
signature for Microsoft Trusted Certificate Authorities. Please note that this
would be helpful for test purposes only since it requires you to install the
certificate in all client browser using the application. Eventually, a
certificate from Trusted Root CA like Verisign, Thawte. Etc has to be bought
for insuring that your CAB/ActiveX component is available for use to all
without security issues. It even makes
code signing easier, which needs only signcode.exe utility along with the spc
file and private key provided by the CA.

For the list for Microsoft trusted CA’s , click the link below:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsecure/html/rootcertprog.asp

The article uses Ascertia as the CA to obtain the free digital certificate.

Steps for Signing Code

Some of the utilities provided in the process of signing the
code are part of the Microsoft SDK. So we would be having them if we
have any version of .NET installed on our machine.
This works
like a charm if the steps are followed correctly. We just need to execute all
the utilities one by one.

Following is the Procedure for code signing:

1.
Downloading the certificate from Ascertia website

http://www.ascertia.com/onlineCA/Issuer/default.aspx?action=login

This requires the user to register for an account and provide some
information so as to embed it into the certificate.


Please note that the "Name" that you enter will be the name seen on the certificate. When the information
is provided, a prompt will be asked to add the certificate into the
browser's certificate root store. Add the certificate in the "Trusted
Root Certification Authorities" store.

2. Generation of Software Publishing Certificate (spc)

Run certmgr.exe. This

would display the certificate installed in the previous step along with other
certificates. Select the option to export without the private key and in DER
encoded binary. This should produce a certificate file with .cer
extension. Put it in a folder and at a path, which is not cumbersome. E.g.
c:\<foldername>. Put all the utility files in this folder too.


Now convert the certificate file to spc file - Software
Publishing Certificate with the following utility


cert2spc <insert cer file path>
<insert new spc file path>


This is the file, which is provided by the Verisign along
with a private key. We will generate a private key later in this stage.
3.

3. Generation of Personal Information Exchange file (pfx)

Run certmgr.exe again. Select the same certificate, and
export again.


This time export the private key. Make sure "Include all certificates in
the certification if possible" is checked and "Delete the
private key if the export is successful" is unchecked.

This will export a pfx file. (Make sure to remember the password you set.)

4. Installation of OpenSSL

This is available from
the following link for Windows Version.
http://www.shininglightpro.com/products/Win32OpenSSL.html

Execute the following code

openssl pkcs12 -in <insert pfx
file path> -nocerts -nodes -out <insert new pem file path>

This will create a *.pem file.

The pfx password will be asked.


5. Generation of Private Key

Transform the *.pem file to a *.pvk file. This pvk
file will be our private key. Along with the spc, it will be used to sign
our CAB file.

Download the pvk transform utility. This file can be found at http://support.globalsign.net/en/objectsign/PVK.zip.

pvk
-in <insert pem file path> -topvk -out <insert new pvk file path>

This is what we require. We only need the spc and pvk
files, so we can delete the other data files if we want.

6. Sign the Code

Now we sign the code using the signcode.exe utility with the
help of spc and pvk files.

The following can be
kept in batch file and executed

set
Product=Picis Ftp

set File=PicisActiveX.CAB

set TimeURL=http://timestamp.verisign.com/scripts/timstamp.dll

signcode.exe
-spc <insert spc file> -v <insert pvk file> -n
"%Product%" -t "%TimeURL%" "%File%"

We can verify the signature by opening
the properties of the signed file, and clicking the Digital Signatures tab. If
there is no Digital Signatures tab, then there is something wrong that we
have done in our procedure.


If everything goes right,
then we have our code digitally signed by Ascertia CA and we can go and use our
activeX to install in our IE 6 and IE 7 browsers.

It really proved helpful to me to test my ActiveX Component for IE 7 Browser. Hope it proves useful to you guys too.

Wednesday, September 6, 2006

Using Single Sign On in Multiple Applications Sharing Same Domain

Using Forms Authentication

Forms Authentication should be used for Single sign on into Multiple Applications.

<authentication mode="Forms">
<forms name=".Website" loginUrl="login.aspx" protection="All" timeout="30" path="/"/>
</authentication>

where ".Website" is the name of the Cookie used to store user credentials for form authentication


Modifying the Machine Key

The
machineKey element might be configured in the machine.config file or on
every web.config application file sharing the Same Cookie. By Default
the encryption key to encrypt cookie data is set to something like this
in the machine.config file:

<machineKey
validationKey="AutoGenerate,IsolateApps"
decryptionKey= "AutoGenerate,IsolateApps"
validation="SHA1"/>

The "IsolateApps" means that a different key will be AutoGenerated for each
application. This setting can be overridden by writing the following
code in the Application's Web.config file:

<machineKey

validationKey=
"C50B3C89CB21F4F1422FF158A5B42D0E8DB8CB5CDA1742572A487D9401E3400267682B202B746511891C1BAF47F8D25C07F6C39A104696DB51F17C529AD3CABE"

decryptionKey= "8A9BE8FD67AF6979E7D20198CFEA50DD3D3799C77AF2B72F"
validation="SHA1"/>

The Machine key should be the same for all the applications sharing the same cookie (Using SSO).

Creating Domain Level Cookie to share same information between Applications

Here, we are using two domains:
http://secure.website.net and
http://www.website.net

The
cookies will be stored in different files and will not be accessible to
both applications. In order to make it work, we will need to create
domain-level cookies that are visible to all sub-domains:

Dim
fat As FormsAuthenticationTicket = New FormsAuthenticationTicket(1,
Login1.UserName, DateTime.Now, DateTime.Now.AddYears(1), False, "")
Dim cookie As HttpCookie = New HttpCookie(".Web20Tools")
cookie.Value = FormsAuthentication.Encrypt(fat)
cookie.Expires = fat.Expiration
cookie.Domain = ".website.net"
Response.Cookies.Add(cookie)


Here,
"cookie.Domain" specifies the name of the domain by which the cookie
would be created. Hence if the Windows user has logged in with the
account name as "Admin", the cookie would be created by the name:
Admin@website.net

The
Data Of Expiry is exactly one year after the date of creation. The
ticket name would be the same as the user name. So this can be
decrypted on the other applications page Load when the request is
redirected to another application.

The cookie is encrypted and
then added to the response stream. This cookie can now be shared by any
application sharing the same subdomain name

Note: For Domain
wide authentication scenarios, you can set domain-wide cookie only for
second level domain, or for third level domain if second level domain
contains three or less characters. It means that you cannot set cookie
for domain "com" or "co.in", but can for "example.com" or
"example.co.in".

Simulation of the Live Site

Now to simulate the setup of the live sites, we need to add entries into the Hosts file, which is present at:
C:/WINDOWS/SYSTEM32/DRIVERS/ETC (Windows XP)
C:/WINNT/SYSTEM32/DRIVERS/ETC (Windows 2000, NT)

The entries would be as follows:

127.0.0.1 www.website.net
127.0.0.1 secure.website.net

This
would help emulate the site on local server so that the cookies can be
shared. The applications can be accessed after creating their virtual
directories:

http://www.website.net/website/default.aspx
http://secure.website.net/shoppingcart/default.aspx

Now to check whether the cookie has been created or not, the cookie created can be found at:
C:\Documents and Settings\Default User\Local Settings\Temporary Internet Files\

where "Default user" will be the name of the user who has logged in.

An
alternative method to check the cookie creation is to go to the
Internet Explorer's Tools Menu -> Internet Options -> Click on
Privacy Tab -> Click Advanced Button .
select "Override Automatic
Cookie Handling" and then select the radio buttons for "First Party
Cookies" and "Third Party Cookies" as "Prompt".

Doing this will enable prompting before cookie creation where the cookie name and the date of expiry can be tracked.


Logging Out of the Application

While
Logging out of the application, the Expiration date of the Cookie
should be set to a past date for the cookie to get deleted. The cookie
should be fetched first using the httpcontext class and then the expiry
date should be changed.

Dim httpWebcookie As HttpCookie
httpWebcookie = Request.Cookies(".Website")
httpWebcookie.Domain = ".website.net"
httpWebcookie.Expires = DateTime.Now.AddYears(-3)
Response.Cookies.Add(httpWebcookie)