15 July 2011

Refer one aspx page to another aspx page or ascx page in asp.net

Refer one aspx page to another aspx page or ascx page in asp.net

add the code in aspx page or User control page .ascx code below

Support.aspx is the reference page

<%@ Reference Page="~/Support.aspx" %>


6 July 2011

HTTP Modules in asp.net

HTTP Modules in asp.net

An HTTP module is an assembly that is called on every request made to your application.
HTTP modules are called as part of the ASP.NET request pipeline and have access to
life cycle events throughout the request.
HTTP modules therefore give you the opportunity to examine incoming and outgoing requests
and take action based on the request.

Typical uses for HTTP modules include:

Security.
-Because you can examine incoming requests, your HTTP module can perform custom
authentication or other security checks before the requested page, XML Web service,
or handler is called.

Statistics and logging.
-Because HTTP modules are called on every request, you can gather request statistics and
logging information in a centralized module, rather than in individual pages.

Custom headers or footers.
-Because you can modify the outbound response, you can inject content such as custom header
information into every page or XML Web service response.

HTTP Modules vs Global.asax Files

-You can implement much of the functionality of a module in the application's Global.asax
file, which enables you to respond to application events.

-However, modules have an advantage over the Global.asax file in that they are encapsulated
and can be created once and used in many different applications.

-By adding them to the Global Assembly Cache (GAC) and registering them in the Machine.config file, you can reuse them across applications.



Http Handlers in asp.net

Http Handlers in asp.net

-ASP.NET HTTP handler is the process (frequently referred to as the "endpoint")
that runs in response to a request made to an ASP.NET Web application.

An HTTP handler can be either synchronous or asynchronous.

synchronous handler
A synchronous handler does not return until it finishes processing the HTTP request for
which it is called.

asynchronous handler
An asynchronous handler runs a process independently of sending a response to the user

Uses of Http Handlers

Http Handlers provide us functionality to create user friendly (easy to remember) Urls.

Example




4 July 2011

Get the Function name,Line number,Columnnumber of the Error in C#

//Get the Function name,Line number,Columnnumber of the Error in C#
using System;
using System.Diagnostics;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
try
{
CustomError();
}
catch (Exception ex)
{
StackTrace trace = new System.Diagnostics.StackTrace(ex, true);
MessageBox.Show("Function Name:"+trace.GetFrame(0).GetMethod().Name);
MessageBox.Show("Line Number: " + trace.GetFrame(0).GetFileLineNumber());
MessageBox.Show("Column: " + trace.GetFrame(0).GetFileColumnNumber());
}
}

private void CustomError()
{
throw new Exception("An error has happened");
}
}
}

1 July 2011

What is dotnet Framework?

What is Framework?
-A reusable set of libraries or classes for a software system (or subsystem).

What is dotnet Framework?
-The .NET Framework is an integral Windows component that contains two main components:
the common language runtime and the .NET Framework class library.

common language runtime - Interoperability between languages in dotnet.
.NET Framework class library - Used for Reusability

Dotnet framework used to develop windows ,web,webservices etc


Server.Transfer v/s Response.Redirect in asp.net

Server.Transfer v/s Response.Redirect in asp.net

-Both these are used to transfer one page to another page in asp.net.

-Response.Redirect(“newpage.aspx”) and Server.Transfer(“newpage.aspx”)

Difference between Server.Transfer and Response.Redirect in asp.net

- Response.Redirect sends the request for the new page to the browser then browser
sends the request for the new page to the webserver.
- but in the case of Server.Transfer it directly communicate with the server to change
the page hence it saves a roundtrip in the whole process.
-If you are using Server.Transfer then you can directly access the values,
controls and properties of the previous page
-But in Response.Redirect, it is not possible.

-Server.Transfer retains the original URL in the browser’s address bar.
It just replaces the contents of the previous page with the new one.
-Response.Redirect can be used for both .aspx and html pages whereas Server.Transfer
can be used only for .aspx pages and is specific to ASP and ASP.NET.


29 June 2011

Trigger is Sql Server 2008

Trigger is Sql Server 2008

Trigger Definition

A trigger is a special type of stored procedure that automatically runs when a language event executes. SQL Server includes two general types of triggers:
data manipulation language (DML) and data definition language (DDL) triggers. DML triggers can be used when INSERT, UPDATE, or DELETE statements modify data
in a specified table or view. DDL triggers fire stored procedures in response to a variety of DDL statements, which are primarily statements that begin with
CREATE, ALTER, and DROP. DDL triggers can be used for administrative tasks, such as auditing and regulating database operations.
Types of DML Triggers

AFTER Triggers

AFTER triggers are executed after the action of the INSERT, UPDATE, or DELETE statement is performed.
Specifying AFTER is the same as specifying FOR, which is the only option available in earlier versions of Microsoft SQL Server.
AFTER triggers can be specified only on tables.

INSTEAD OF Triggers

INSTEAD OF triggers are executed in place of the usual triggering action. INSTEAD OF triggers can also be defined on views with one or more base tables,
where they can extend the types of updates a view can support.

For more information about AFTER and INSTEAD OF triggers, see DML Trigger Planning Guidelines.

CLR Triggers

A CLR Trigger can be either an AFTER or INSTEAD OF trigger. A CLR trigger can also be a DDL trigger.
Instead of executing a Transact-SQL stored procedure, a CLR trigger executes one or more methods written in managed code that are members of an assembly
created in the .NET Framework and uploaded in SQL Server.

DDL Triggers
-DDL triggers execute in response to a variety of data definition language (DDL) events.
These events primarily correspond to Transact-SQL CREATE, ALTER, and DROP statements, and certain system stored procedures that perform DDL-like operations.

- Unlike DML triggers, they do not fire in response to UPDATE, INSERT, or DELETE statements on a table or view. Instead, they fire in response to a variety of
Data Definition Language (DDL) events. These events primarily correspond to Transact-SQL statements that start with the keywords CREATE, ALTER, and DROP. Certain
system stored procedures that perform DDL-like operations can also fire DDL triggers
DDL triggers can be used for administrative tasks such as auditing and regulating database operations.

Use DDL triggers when you want to do the following:

-You want to prevent certain changes to your database schema.

-You want something to occur in the database in response to a change in your database schema.

-You want to record changes or events in the database schema.


DDL triggers fire only after the DDL statements that trigger them are run. DDL triggers cannot be used as INSTEAD OF triggers.

The following example shows how a DDL trigger can be used to prevent any table in a database from being modified or dropped.

CREATE TRIGGER safety
ON DATABASE
FOR DROP_TABLE, ALTER_TABLE
AS
PRINT 'You must disable Trigger "safety" to drop or alter tables!'
ROLLBACK ;
DML Triggers

DML triggers are invoked when a data manipulation language (DML) event takes place in the database. DML events include INSERT, UPDATE, or DELETE statements that modify data in a specified table or view. A DML trigger can query other tables and can include complex Transact-SQL statements. The trigger and the statement that fires it are treated as a single transaction, which can be rolled back from within the trigger. If a severe error is detected (for example, insufficient disk space), the entire transaction automatically rolls back.

DML triggers are useful in these ways:

-They can cascade changes through related tables in the database; however, these changes can be executed more efficiently using cascading referential
integrity constraints.
-They can guard against malicious or incorrect INSERT, UPDATE, and DELETE operations and enforce other restrictions that are more complex than those defined with
CHECK constraints.
-Unlike CHECK constraints, DML triggers can reference columns in other tables. For example, a trigger can use a SELECT from another table to compare to the inserted
or updated data and to perform additional actions, such as modify the data or display a user-defined error message.
-They can evaluate the state of a table before and after a data modification and take actions based on that difference.
Multiple DML triggers of the same type (INSERT, UPDATE, or DELETE) on a table allow multiple, different actions to take place in response to
the same modification statement.


Types of DML Triggers

You can program the following types of DML Triggers:

AFTER Triggers

AFTER triggers are executed after the action of the INSERT, UPDATE, or DELETE statement is performed.
Specifying AFTER is the same as specifying FOR, which is the only option available in earlier versions of Microsoft SQL Server.
AFTER triggers can be specified only on tables.

INSTEAD OF Triggers

INSTEAD OF triggers are executed in place of the usual triggering action. INSTEAD OF triggers can also be defined on views with one or more base tables,
where they can extend the types of updates a view can support.

For more information about AFTER and INSTEAD OF triggers, see DML Trigger Planning Guidelines.

CLR Triggers

A CLR Trigger can be either an AFTER or INSTEAD OF trigger. A CLR trigger can also be a DDL trigger. Instead of executing a Transact-SQL stored procedure,
a CLR trigger executes one or more methods written in managed code that are members of an assembly created in the .NET Framework and uploaded in SQL Server.


Implementing OAuth validation in a Web API

 I mplementing OAuth validation in a Web API Implementing OAuth validation in a Web API using C# typically involves several key steps to sec...