Tuesday, May 13, 2008

WEB.config of ASP.Net



Web.Config in Asp.Net

Need of Web config file
The webconfig file is used to configure the general settings to the iis and the sourceASP.NET uses these web.config configuration files to hierarchically compute a unique collection of settings for each incoming URL target request (these settings are calculated only once and then cached across subsequent requests; ASP.NET automatically watches for file changes and will invalidate the cache if any of the configuration files change).And redirect or set the setting
Basically it’s a XML based file and Each web.config file applies configuration settings to the directory it is located in and to all virtual child directories beneath it
Configuration Section
A web.config file is an XML-based text file that can contain standard XML document elements, including well-formed tags, comments, text, cdata, and so on. The file may be ANSI, UTF-8, or Unicode; the system automatically detects the encoding. The root element of a web.config file is always a tag. ASP.NET and end-user settings are then encapsulated within the tag, as follows:
All configuration information resides between the and root XML tags. Configuration information between the tags is grouped into two main areas: the configuration section handler declaration area and the configuration section settings area.
Configuration section handlers - The ASP.NET configuration infrastructure makes no assumptions regarding the file format or supported settings within a web.config file. Instead, it delegates the processing of web.config data to configuration section handlers, .NET Framework classes that implement the IConfigurationSectionHandler interface. An individual IConfigurationSectionHandler declaration needs to appear only once, typically in the machine.config file. The web.config files in child directories automatically inherit this declaration. Configuration section handlers are declared within a web.config file using section tag directives nested within a tag. Section tags may be further qualified by section group tags to organize them into logical groups (see below). Each section tag identifies a tag name denoting a specific section of configuration data and an associated IConfigurationSectionHandler class that processes it.
Configuration section groups - ASP.NET configuration allows hierarchical grouping of sections for organizational purposes. A tag may appear inside a tag or inside other tags. For example, ASP.NET section handlers all appear within the section group.


Configuration sections - ASP.NET configuration settings are represented within configuration tag sections, also nested within a tag (and optional section group tags). For each configuration section, an appropriate section handler must be defined in the config hierarchy. For example, in the sample below, the tag is the configuration section that defines the HTTP modules configuration data. The
System.Configuration.HttpModulesConfigurationHandler
class is responsible for interpreting the content contained within the tag at run time. Note that both the section handler definition and the section must have the same section group qualifier (in this case, ). Also note that tag names are case-sensitive and must be typed exactly as shown. Various attributes and settings for ASP.NET are also case-sensitive and will not be examined by the configuration runtime if the case does not match.
Using Location and Path
By default, all configuration settings defined within the top-level tag are applied to the current directory location of the containing web.config file and to all of the child paths beneath it. You can optionally apply configuration settings to specific child paths under the current config file by using the tag with an appropriately constraining path attribute. If the config file is the main machine.config file, you can apply settings to specific virtual directories or applications and the virtual path needs to include the friendly name of the site like, , which is also shown in the example below. If the config file is a web.config file, you can apply settings to a specific file, child directory, virtual directory, or application. _______________________________________________________________________
Here I do give a simple example to connect with Sql Server or Oracle





//To get the values of the connections strings you would use


string conn = ConfigurationSettings.AppSettings["ORACLEConnectionString"];
OleDbConnection myConnection = new OleDbConnection(conn);

//When the site goes live change the debug setting to false which will make the site have a little better //performance.



//Customer errors can be handled be turned off but I prefer them to be turned on as below.


Or






//Application Tracing can be set up while shows the output times and all sorts of info of every page if you //set it the values to true below. Local only would mean only onthe webserver hosting the site. You can also //do per page tracing so that you can turn off applicationTracing and have trace="true" at the top of a single //page.

Wednesday, May 7, 2008

Multi tier Architecture

Why Multi tier Architecture is better

Hai Dear friends Here am taking you all to the small tour in Multi tier architecture or n tier architecture,

Multi Tier Architecture
In the concept of software engineering while the development of software we can develop the modules in Different layers
Each of the layer will be inherited from the another layer
Let me explain hat to you trough a simple example,
In a software we need to process the data from the database ,so usually we will write the program in the first layer to access data if we need to repeat the function we use the same function in many areas right ? ok so tell me if the provider(the connectivity to the Database ) is changed from access to oracle or you need to use two providers then how will you handle , you have to rewrite all the codes written for the database access right , so we will divide the operations to multiple steps each steps are put in each Layers , and Lets Look it Trough some Layers

DAL(Data Access Layer)
In Data Access Layer we will write the Functions to process the database directly like may be direct query execution or by using stored procedures ,and the function can be have arguments and all function can take required providers as like they need .
BLL(Business Logic Layer )
It act as the intermediate between Dal and UI Part Like the Arguments from the user is handled and converted to the require type and the returned answers will be converted to the users required form to the BLL variable for an example is the a field name ‘stafftype’ return the data like ‘T’ “N’ or null here in bll we will convert the variables like
if ‘T’ then ‘Teaching’
if ‘N’ Then Non Teaching”
else ‘Not Defined’

like we can do many manipulations so this manipulated result will be send to the UI part which in shown to the end user

UI (User Interface layer)
In an application the Part is just behind the design window like Btn_OnClick() in this we can call the functions in BLL
And at General the UI calls the Functions From BLL and the BLL after required Handling it send to DAL and the DAL Returns the out put again the out put send to bll again the BLL manipulate the result and send to the UI

User=>UI =>BLL(manipulation)=>DAL(process and output) =>BLL(manipulation)=>UI=>User

Advantage
If we any major change in the Provider like change to SQL to oracle or some major change in data types and structure ; we need to change only the small portion in DAL and BLL so the user will get the Good Result ,So this Technology is More Stretchable and Flexible and adoptable
--------------------------------------------------

Monday, May 5, 2008

.Net ,Asp.Net,.Net Frame Work

Why ASP.Net
The Active Server Page is a Concept where the requests will be send to the server and the server returns the result as the html to the browser

So that the intermediate user cannot know what is happening behind while seeing the source from the browser
So it can be tell as server side scripting
And it runs inside IIS (Internet Information Services) Microsoft's Internet server
How Does Is Works
When a browser requests an HTML file, the server returns the file according to the request
The request will be send trough the iis to the Asp.Net Engine
The ASP.NET engine reads the file, line by line, and executes the scripts in the file
And returns the result as HTML File
How .Net Works



Code Behind
The code behind tense that the sap requests can be send to the server in the iis and asp engine understandable form and the
Codes like c#.net ,vb.net will be compiled by the Compilers and convert to MSIL(Microsoft intermediate Language
And again the MSIL have to be converted to M.L(machine language )
This is done by the help of CLR(Common Language Run Time)
And The JIT(just in time compiler)
Like shown bellow
-------------------------
C#.Net,asp.Net,Etc

Compilers

MSIL

JIT

CLR

ML
NB : asp.Net is not the upgraded version of the asp but its really a new Generation of the ASp



Why .Net Frame Work


The .NET Framework is the infrastructure for the new Microsoft .NET Platform. The .NET Framework is a common environment for building, deploying, and running Web Services and Web Applications.
The .NET Framework contains common class libraries - like ADO.NET, ASP.NET and Windows Forms - to provide advanced standard services that can be integrated into a variety of computer systems.
The .NET Framework is language neutral. Currently it supports C++, C#, Visual Basic, JScript (The Microsoft version of JavaScript) and COBOL. Third-party languages - like Eiffel, Perl, Python, Smalltalk, and others - will also be available for building future .NET Framework applications.
The new Visual Studio.NET is a common development environment for the new .NET Framework. It provides a feature-rich application execution environment, simplified development and easy integration between a number of different development languages.

Sql Query Injection

Sql Query Injection:
is a technique used to pass some conditions as the query string
Like if the password is checked by the query from code the encrypted password and the user name will be send to the database as the query string ,
So if is returns null then the remaining operation will be failed

So we can return a true value by passing a always true statements
Like
select 'rubin' as uname ,'done' as process where 1<2
This will be always true
So we use stored procedures to avoid such problems
And by validation the query string by adding an security module by the user we can avoid this query injection

Why Stored Procedures

The stored procedure are used in order to speed up database services
How
1)The Stored Procedures are Basically executed in the client side database engine so that Is can use all the privileges by the database Engine
2) in order to design the procedure basically we pass some command line arguments so the other hackers cant easily retrieve the data
3) The query injection (which is described in the next topic ) can be avoided
4) in Sql Server we can use ‘create procedure ‘ (arguments)
For the procedure creation
Example

CREATE PROCEDURE dbo.usp_ name
(
@Argument )
AS
SET NOCOUNT ON;
SELECT fields FROM tablename
WHERE (Keyvalue= @argument codition)
GO

Here the procedure is used to get a Data From DB by a condition

Even we can use
If condition
Else
End
In the SQL DB like the same above procedure can be used to access all value and a conditioned value
CREATE PROCEDURE dbo.usp_ name
(
@Argument )
AS
SET NOCOUNT ON;
If @Argument=null
begin
SELECT fields FROM tablename
End
Else
Begin
SELECT fields FROM tablename
WHERE (Keyvalue= @argument codition)
end
GO

Here if we passed null as argument then is will select all value else search by the Condition
Like this we can use all the sql statements in the stored procedures