Ramani Sandeep's Blog

DotNetting – Fast , Easy Way of Developing Applications

Archive for July, 2009

LINQPad

Posted by Ramani Sandeep on July 31, 2009

Tired of querying in antiquated SQL?

Well, you don’t have to!  LINQPad lets you interactively query SQL databases in a modern query language: LINQ.  Say goodbye to SQL Management Studio!

LINQPad supports everything in C# 3.0 and Framework 3.5:

    * LINQ to Objects
    * LINQ to SQL
    * Entity Framework
    * LINQ to XML
    * (Even old-fashioned SQL!)

LINQPad is also a great way to learn LINQ: it comes preloaded with 200 examples from the book, C# 3.0 in a Nutshell.  There’s no better way to experience the coolness of LINQ and functional programming.

And LINQPad is more than just a LINQ tool: it’s a highly ergonomic code snippet IDE that instantly executes any C#/VB expression, statement block or program – the ultimate in dynamic development. Put an end to those hundreds of Visual Studio Console projects cluttering your source folder!

Best of all, LINQPad standard edition is free and can run without installation (or with a low-impact setup). The executable is 3MB and is self-updating.

Download Now : http://www.linqpad.net/

Posted in SQL Server | Tagged: | Leave a Comment »

Securing Cookies Data

Posted by Ramani Sandeep on July 30, 2009

Introduction

I really have some good laughs when I tamper with cookies on my machine and watch the results when it is submitted back to the site. On the other hand, I don�t want any one to do the same to the cookies that I make!

Cookies, most of the times, shouldn�t be in plain text, at least, they should be tamper-proof! Revealing the content of your cookies might give curious and malicious people an idea about your application�s architecture, and that might help hacking it.

ASP.NET encodes and hashes its authorization ticket, making it secure and tamper-proof. However, the methods used to secure authorization cookies are inaccessible from outside the .NET framework libraries, so you can�t protect your own cookie using these methods; you need to protect it yourself using your own encryption key, encoding and hashing algorithms. HttpSecureCookie works around this by accessing the same methods ASP.NET uses for cookie authorization.

Of course, you shouldn�t save valuable information in your cookies, but if you have to, then this library is at your disposal.

Background

Before you start using this code, if you do not know what MachineKey is, I highly recommend checking this MSDN article: How To: Configure MachineKey in ASP.NET 2.0.

ASP.NET uses the System.Web.Security.CookieProtectionHelper internal class to decode and encode the content of a cookie before submitting it to the client. This class is based on the MachineKey. I wonder why Microsoft kept this class internal!?

To be able to access this internal class, I had to use reflection to be able to access the Decode and Encode methods of CookieProtectionHelper.

Eric Newton has a similar and good article on CP: Encrypting cookies to prevent tampering. However, that code is made for .NET 1.1 and it doesn’t work with .NET 2.0 (but it does with some modifications); moreover, its resulting cipher text is in binary format versus being in encrypted format, and I don’t know if this is a security risk. Also, I am accessing a higher level class System.Web.Security.CookieProtectionHelper than the one used by that article, System.Web.Configuration.MachineKey, to obtain the cryptography service, and that saved me time by not writing some low level code.

There is also another available method for encoding cookies, by using the FormsAuthenticationTicket and FormsAuthentication.Encrypt; for more information, check the section "Creating the Forms Authentication Cookie" on Explained: Forms Authentication in ASP.NET 2.0. However, I believe, the method mentioned in this article is more flexible.

Click here to Read more….

Posted in ASP.NET | Tagged: , , | Leave a Comment »

ASP.NET Security: 8 Ways to Avoid Attack

Posted by Ramani Sandeep on July 30, 2009

Adding security to Web apps may not be great fun but it doesn’t have to hard. You can easily ensure your apps meet today’s best practices by applying eight principles for secure Web development.

Building ASP.NET Web applications has never been easier. Visual Studio.NET hides so many technical details behind the scenes that developers need only concentrate on the core business logic. However, hackers are on the lookout for any opportunity to hack into your application. Which means the pressure is on you to keep defense top of mind. If you don’t, you’ll quickly find your ASP.NET apps vulnerable to attack.

I’ve compiled a list of the eight most vital defenses, complete with the information you need to arm yourself against them.

 

Click here to Read more….

Posted in ASP.NET | Tagged: , | 1 Comment »

SQL Database Publishing wizard is now in Visual Studio 2008.

Posted by Ramani Sandeep on July 24, 2009

The SQL database publishing wizard is a very popular web-downloadable add-in for Visual Studio 2005. The publishing wizard addresses the issue where a developer needs to deploy a local database from his development machine to a hosting environment on a remote machine. We received a lot of positive feedback for this wizard and we decided to integrate this with Visual Studio 2008. This is a feature that was added post Beta2 and will be available with Visual Studio 2008 RTM.

The wizard supports two key database hosting deployment scenarios:

1. It generates a single .SQL script file which can be used to recreate a database on a remote machine

Using the Database Publishing Wizard  you can point to a database on your local machine, and then automatically create a .SQL script file that contains the setup logic needed to re-create a replica of the database on any remote system – for example an external hosting system. This .SQL script includes everything needed to create the database schema (tables, views, sprocs, triggers, full-text catalogs, roles, rules, etc). You also have the option of populating the new database with the same data contents as your local tables. Most hosters today support the upload and running of .SQL files to their hosted environments using their admin control panels. So, all you need to do is upload and run the .SQL script generated by the Database Publishing Wizard, and you will have a working database in your hosted environment. This should considerably reduce the effort required to deploy your databases.

2. It connects to a web service provided by your hoster and directly creates objects on a specified hosted database.

The Database Publishing Wizard also enables you to point at a database you are working with on your local system, and then use web-services to transfer and recreate the database in your remote hoster environment (without you having to create the .SQL file or use the hoster admin control panel to run it).  This publishing option does require that a SQL Publishing web-service be exposed in the hosting environment, and the SQL Server Hosting Toolkit includes a free implementation of this SQL Publishing web-service that we’ll be working with hosters to aggressively deploy

 

Clicl here to Read more ….

Posted in SQL Server | Tagged: | Leave a Comment »

Dynamic creation of Insert, Update, Delete Stored procedure

Posted by Ramani Sandeep on July 23, 2009

Introduction

It is easy to write Insert, Update and Delete stored procedures for a table, but it may take lots of time and effort to write these basic stored procedure. Especially if you have lots of tables with lots of fields. That time might be better spent on other tasks.

I have written a stored procedure to help do this automatically, and this article explains how it works. This stored procedure, sp_et_create_sps_for_table, automates the creation of stored procedures for a table using the table name as a parameter. It dynamically creates the scripts for insert, update and delete stored procedures and then creates them. It gathers the primary key information of the table and creates the necessary scripts for the where clause of the update & delete stored procedures of the given table.

 

Click here to Read more….

Posted in SQL Server | Tagged: , , | 2 Comments »

What is Windows Communication Foundation?

Posted by Ramani Sandeep on July 21, 2009

.NET 3.0 comes with three main technologies in core: Windows Presentation Foundation, Windows Workflow Foundation and Windows Communication Foundation.

Windows Communication Foundation (WCF), codenamed Indigo in Microsoft, is the last generation of service oriented technologies for development.  It provides all the latest means to help developers build service oriented applications.  The result of service oriented design is a distributed system which runs between services and clients.  Windows Communication Foundation is Microsoft infrastructure for Service Oriented architecture.

You have probably worked with Web Services in .NET 1.x or 2.0 and may have some experiences with Remoting.  Windows Communication Foundation is an enhanced technology to provide the same functionality with better features and reduces the time to develop a distributed system.  Web Services and Services are not identical.  One main difference is Web Services use HTTP protocol, but Services can use any protocol and this is an important difference.

Service Orientation

In recent years, development moved from building centralized local systems to distributed systems which run on several places.  Each part of these systems are hosted somewhere and provide some services.  The idea of having services to answer to common needs through the web became serious and development technologies answered to this need by providing Web Services in their core, but day after day distributed systems became more common and the idea of Service Orientation (SO) was born.

Service Orientation is a complement to Object Orientation.  It means you will not kick Object Orientation out to use Service Orientation.  Service Orientation uses Object Orientation in its core, but there are some distributed scenarios that can be viewed by Object Orientation so you use Service Orientation to describe these scenarios.

In Service Orientation you think different and describe things via services and divide your system into smaller parts which run as services.  These services can communicate with others via messages.  In each service you can apply Object Orientation to accomplish goals of that service.  One important benefit of Service Orientation is here because you can use different technologies and platforms to design a service by using Object Orientation then use universal formats to build messages and start communication between different pieces of your system.

There are four principles in Service Orientation (you may see them as tenets on other resources):

  • Boundaries are explicit.
  • Services are autonomous.
  • Services share schema and contract, not class.
  • Service compatibility is determined based on policy.

You can read more about these fundamentals (they are important principles) on MSDN.

Generally, you have to change your point of view in Service Oriented design, but this should not change your view for Object Oriented Programming.  You should get enough experience to divide a system to logical independent services then choose appropriate platform to build each piece.  Thankfully, Microsoft helps you in all stages and you can use powerful Microsoft technologies to build your distributed software.

Service Oriented Architecture (SOA) is a concept beyond the scope of these tutorials.  I recommend you to read good books about Service Oriented Architecture to learn more about it.  Having a good understanding of this architecture is an important requirement to be success in this field.

Advantages

Windows Communication Foundation has some important enhancements in comparison with preceding technologies.

  • It merges all older separate technologies in one place and allows you to do things easier.
  • It has rich communication capabilities.
  • It comes with many powerful and ready to use enterprise features.
  • It can be integrated with other technologies and has great interoperability.

Architecture

Architecture of Windows Communication Foundation consists of five layers.  These layers from top to down are:

  • Application  : In this level application is located.
  • Contracts    : In the second layer service, data and message contracts as well as bindings and policies are present.  In this level services describe themselves to clients.
  • Runtime     : Behaviors are located in this layer.  Runtime layer loads all services.
  • Messaging  : Different types of channels as well as encoders are here.  This layer enables communications for services.
  • Hosting  : This layer is where host services in different manners, but there are two common ways to host a service.  You can host a service in Internet Information Services (IIS) which is easier than the second approach and starts and stops your services automatically.  The second approach is to create executable files (.EXE) for services and start and stop them manually by writing more codes.

This layering allows developers to work on Windows Communication Foundation with different skills because each layer needs different skills.

Programming Model

Windows Communication Foundation has simple and easy to write/understand codes.  It has many APIs, but beside this only a small amount of these API’s is common.

There are three programming approaches in Windows Communication Foundation:

  • Imperative                 : You use programming codes in different languages to accomplish a task.
  • Configuration Based  : You use configuration files to do things.
  • Declarative                 : You use attributes to declare something.

In general, you will declare contracts and behaviors using attributes, configure endpoints, security and some other settings in configuration files and will implement service methods logic in codes.

On the other hand, you can use typed services and untyped services.  In typed services you pass normal objects and data types and/or get normal objects and data types, but in untyped services you pass and get messages to work directly with messages at a lower level.

Other useful articles

Posted in WCF | Tagged: , , | Leave a Comment »

Repeater with Paging and Sorting Features

Posted by Ramani Sandeep on July 21, 2009

Introduction

In order to create a dynamic page, we need some server side control to do repetitive work and create the page. There are lots of controls provided by Microsoft .NET, i.e. DataList, DataGrid, GridView, Repeater and many more.

Background

I love to use Repeater as it is light weight and if I need it only for showing data. One of the drawbacks of using Repeater is that it does not have in-built functionality for Paging and Sorting. This article will be helpful to people who need a light weight control and also want to use Paging and Sorting.

Read more…

Posted in ASP.NET | Tagged: | 1 Comment »

Intersect, Except, Union, All and Any

Posted by Ramani Sandeep on July 21, 2009

I was reviewing the Microsoft training courses for SQL2008 for a set of application developers who wanted to learn more about SQL Server. In doing so I came across some commands that I either had not heard of or had not used before.

  • INTERSECT
  • EXCEPT
  • ALL
  • ANY

ALL and ANY have been around for donkeys years but INTERSECT and EXCEPT were new to me.

Whenever I find a new set of commands in T-SQL I fire up my developer edition and go straight to Adventureworks to start playing around.

 

Visit this link to read more…

Posted in SQL Server | Tagged: , , , | Leave a Comment »

How to Create Meta Tags Programmatically in ASP.NET 2.0

Posted by Ramani Sandeep on July 17, 2009

If you have been Developing Web, you may be familiar with the meta tags in an HTML page. The meta tags are used to provides keywords etc in an HTML page.

Now in ASP.NET 2.0, you can add these meta tags programmatically. The HtmlMeta class provides programmatic access to the HTML <meta> element on the server. The HTML <meta> element is a container for data about the rendered page, but not page content itself.

The Name property of HtmlMeta provides the property name and the Content property is used to specify the property value. The Scheme property to specify additional information to user agents on how to interpret the metadata property and the HttpEquiv property in place of the Name property when the resulting metadata property will be retrieved using HTTP.

The following code shows how to add meta tags to a page programmatically.

HtmlMeta metaTag = new HtmlMeta();
metaTag.Name = "Keywords";
metaTag.Content = "Ramani Sandeep, Sandy, Sandeep , Sam";
this.Header.Controls.Add(metaTag);

Add the above created method to Load event of the Page. Now The Result can be seen by viewing dynamically cretaed source of the Page.

Similarly, you can add multiple meta tags to the header of the Page.

You can also add sechema to the Contact.

// Render: <meta name="date" content="2006-03-25" scheme="YYYY-MM-DD" />
meta = new HtmlMeta();
meta.Name = "date";
meta.Content = DateTime.Now.ToString("yyyy-MM-dd");
meta.Scheme = "YYYY-MM-DD";
this.Header.Controls.Add(meta);

Posted in ASP.NET | Tagged: | Leave a Comment »

Important Silverlight Tutorials for Beginners

Posted by Ramani Sandeep on July 3, 2009

Technorati Tags:

Important FAQ questions for WPF and SilverLight:

  • What is the need of WPF when we had GDI, GDI+ and DirectX?
  • How does hardware acceleration work with WPF?
  • Does that mean WPF has replaced DirectX?
  • So can we define WPF in a precise way?
  • What is XAML?
  • So is XAML meant only for WPF ?
  • Can you explain the overall architecture of WPF?
  • Which are the different namespaces and classes in WPF ?
  • Can explain the different elements involved in WPF application practically?
  • What are dependency properties?
  • Are XAML file compiled or built on runtime?
  • Can you explain how we can separate code and XAML?
  • How can we access XAML objects in behind code?
  • What kind of documents are supported in WPF?
  • What is SilverLight ?
  • Come on, even WPF runs under browser why SilverLight ?
  • Can SilverLight run in other platforms other than window?
  • What is the relationship between Silver Light, WPF and XAML?
  • Can you explain SilverLight architecture?

             click here to read more ……

 

SilverLight FAQ part 2 (Animations and Transformations)

  • What is the definition of animation from Silver light perspective?
  • What is a timeline in Silver light?
  • What are the different kinds of animation supported by Silverlight?
  • Can you explain doubleanimation , coloranimation and pointanimation ?
  • What is a story board?
  • Can we see a simple silverlight animation to just get started?
  • What are the different ways in which silver light does transformation?
  • Silverlight VS Flash good news and bad news

         click here to read more…

 

SilverLight’s FAQ – Part 3

    Technorati Tags:
  • Can you explain one way and two way bindings?
  • Can you explain One time binding?
  • Can you demonstrate a Simple example of OneWay and TwoWay?
  • What are the different ways provided to do layout in SilverLight?
  • Can you explain how Canvas layout actually works?
  • How can we implement Grid Layout?
  • How can we implement Stack Layout?
  • What are the different steps involved in consuming WCF service in Silverlight?
  • Why can’t we consume ADO.NET directly in SilverLight?
  • How can we do database operation using SilverLight?

        click here to read more…

Posted in WPF / Silverlight | Tagged: | Leave a Comment »