Posts

Showing posts from July 19, 2009

An Overview of Authentication and Authorization Options in ASP.NET

Image
Security 101: Authentication and Authorization Authentication and Authorization are two interrelated security concepts. In short, authentication is a process of identifying a user, while authorization is the process of determining if an authenticated user has access to the resource(s) they requested. Typically, authentication is achieved by the user sharing credentials that somehow verify the user's identity. Whenever a user logs on to an application, the user is first authenticated and then authorized. With ASP.NET Web applications, the users requesting a page are, by default, anonymous . There are different techniques available for determining the identity of an anonymous user, which we'll examine in this article. Realize, however, that, by default, Web applications allow for anonymous access. This article provides a high-level overview of the authentication and authorization models available in an ASP.NET Web application. Understanding how ASP.NET and IIS Handl

Cookieless ASP.NET forms authentication

Cookieless forms authentication Why, when? They say, its not possible. Well it is, and relatively easy to accomplish! Lot of companies and people want to exclude cookie usage from their lives. Partly because its said to be insecure, partly because they see no reason to use it. In my case, it was mandatory not to use cookies, but make a forms login page. Of course I've started with the normal forms authentication, cause I believed, that the big brother couldn't make such a mistake, to use cookies. They did. After searching all the forums how to skip cookie usage, all I've found was this: The hard way If you pass the encoded cookie as a GET parameter to the Response.Redirect() function, the system will work as normal: the user will be signed in until the parser can find the cookie as a GET parameter, or a cookie is not easy, and makes no sense at all. The code snippet to accomplish the "get" way of cookieless authentication is: See full detail:

How To Read File Attributes using OLE Object with SQL Server

Introduction This article will demonstrate how we can read file attributes using OLE Object with SQL Server. Here are a number of T-SQL Stored Procedures, based on the use of the FileSystem Object (FSO) that may just get you out of a tight corner. Background It is not necessary that developers must use a .NET class library for getting file attributes information when the application is completely based on DBMS. It is always better to use the standard techniques provided by SQL Server where possible. SQL Server provides several "standard" techniques for file manipulation based on the use of the FileSystem Object (FSO). Using the Code Thankfully, when armed with OLE Automation and the FileSystem Object (FSO), all sorts of things are possible. The FileSystem Object was introduced into Windows to provide a single common file-system COM interface for scripting languages. It provides a number of handy services that can be accessed from T-SQL. I'll provide a f

Reading Files in SQL Server Using T-SQL

Introduction SQL Server provides several "standard" techniques for file manipulation but, sometimes, they aren't quite up to the task at hand – especially when dealing with large strings or relatively unstructured data. Here are a number of T-SQL Stored Procedures, based on the use of the FileSystem Object (FSO) that may just get you out of a tight corner. Background SQL Server has never been short of ways to read from files, and it is always better to use the standard techniques provided by SQL Server where possible. However, most of them are really designed for reading tabular data, and aren't always trouble-free when used with large strings or relatively unstructured data. For reading tabular data from a file, whether character-delimited or binary, there is nothing that replaces the hoary old Bulk Copy Program (BCP), which has more esoteric methods such as Bulk Insert. It is possible to read text-based delimited files with ODBC; simple files can be r

Converting a DataSet to a Generic List

Image
Introduction In this article, I present a set of classes that can be used to create a generic List < T > from a specified DataSet object. This could be useful in cases where we have data for a specified entity loaded into a DataSet and need to easily construct a generic List < > of that entity type. To demonstrate the usage, we will consider the following scenario: We have to get an Address Book application running. We are using a database for storage, and have created the following tables: Contact - Contains details about a contact Address - Contains details about an address ContactAddress - Maps a contact to multiple addresses With this data model in mind, we proceed to write two stored procs, one to get all contacts in the system, and one to get the contact details given the contact ID. While listing all contacts, we only need the contact ID and the contact name to be displayed. While getting the contact details, we need all the contact details and

Extending Excel with .NET

Image
Introduction Using 'Excel' as search keyword results in almost 700 CodeProject articles. Admittedly quite a few of these articles address Excel at best tangentially, but none of the ones actually focussing on Excel 'seem' to have addressed a very simple question: how to create menu items in the Excel application that allow the user to interact with code written in .NET without resorting to VSTO or the development of add-ins. This article is intended to fill this void. I intend to provide an easy way to create and interact with custom Excel menu items without having to resort to Microsoft's Visual Studio Tools for Office (VSTO) or Visual Basic for Applications (VBA). This approach takes advantage of the .NET platform and the VB and C# object models for MS Excel which have been illustrated in a number of previous CodeProject articles. In the interest of space I am referencing only two that I found particular helpful. Modifying MS Excel's menu is rat

Upload a CSV file into a Gridview

Image
You have a CSV file and you would like to display it in a Gridview. This bit of code was born out of a desire to allow user's to see their CSV contents inside of a Gridview. Once the user had a chance to see it they could click a button to move to the next step. This following code will take the CSV and turn it into a dataTable that will be able then bound to a Gridview. This makes it easy to further manipulate your data or even saving the dataTable to session for future use. THE CODE: Drop a FileUpload control on your canvas as well as a Button for submitting the file and a Gridview control. Then add the System .IO, your Variables, and the Click Event to the Button. Imports System.IO Partial Public Class _Default Inherits System. Web .UI.Page Dim streamRdr As StreamReader Dim fileLines As String () Dim line As String Protected Sub Button1_Click( ByVal sender As Object , ByVal e As EventArgs) Handles Button1.Clic

Abstract Class vs Interface

Difference Between abstract Class and Interface: It is the most frequent question being asked in .Net world . In this tutorial, I will explain the difference theoretically followed by code snippet. Theoretically there are basically 5 differences between Abstract Class and Interface which are listed as below :- A class can implement any number of interfaces but a subclass can at most use only one abstract class. An abstract class can have non-abstract Methods(concrete methods) while in case of Interface all the methods has to be abstract. An abstract class can declare or use any variables while an interface is not allowed to do so. So following Code will not compile :- interface TestInterface { int x = 4; // Filed Declaration in Interface void getMethod(); string getName(); } abstract class TestAbstractClass { int i = 4; int k = 3; public abstract void getClassName(); } It will generate a compile