Posts tagged "project"

Url Rewriting in Asp.net With Sample Project


URL rewriting is the process of intercepting an incoming Web request and automatically redirecting it to a different URL.

To understand completely follow below link
http://msdn.microsoft.com/en-us/library/ms972974.aspx

In this article I am going make a simple example which will take only few minutes and you will learn how to achieve URL Rewriting.

I believe developer doesn’t have much time to read a complete article of 20 pages.

Here we go

Step 1
Create a table
(
POSTID INT,
TITLE VARCHAR(255),
BODY TEXT
)

CREATE TABLE TESTTABLE

Insert some dummy values

INSERT INTO TESTTABLE (POSTID,TITLE,BODY) VALUES (1,‘ACCORDIAN CONTROL WITH SQL SERVER’,
‘ACCORDIAN CONTROL WITH SQL SERVER CONNECTIVITY JOGGEE
MADE A ARTICLE AND THAT IS THE BEST I THINK SO.’)
GO
INSERT INTO TESTTABLE (POSTID,TITLE,BODY) VALUES (2,‘Mouse over effect’,
‘This is so simple and can found thousand places but I tried to make it more easier who
doesnt know the different between or anchor.’)
GO
?
SELECT * FROM TESTTABLE

STEP – 2
Create a stored procedure
Create PROCEDURE PROC_TEST
AS
BEGIN
SELECT
‘’ + TITLE + ‘’ AS ‘TITLE’,
BODY
FROM TESTTABLE
END

GO

Procedure for Detail Page.
CREATE PROCEDURE PROC_TESTDETAIL
@ID INT
AS
BEGIN
SELECT
POSTID,
TITLE,
BODY
FROM TESTTABLE
WHERE POSTID = @ID
END
GO

Database work is finished, let move to ASP.NET project means Website Programming.
Create a Website, Ajax Enabled or not its up to you, No matter what you choose.

In a default webpage write below code. I am pasting the complete code for Default page. where i am using DataList direct binding with two field. 

In a Code Behind Past below code.

Imports System.Data
Imports System.Data.SqlClientPartial Class _Default
Inherits System.Web.UI.PageProtected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me

Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me .Load
If IsPostBack = False Then
Dim sqlConn As New SqlConnection
Dim sqlCmd As New SqlCommand(“PROC_TEST”, sqlConn)
Dim objDA As New SqlDataAdapter
Dim DT As New DataTable
‘******************************************************************************************************
‘I have mentioned this connection string in the web.config Change it with appropriate values.

‘****************************************************************************************************************
sqlConn.ConnectionString = ConfigurationManager.ConnectionStrings(“connString”).ConnectionString
‘opening a connection
sqlConn.Open()
sqlCmd.Connection = sqlConn
sqlCmd.CommandType = CommandType.StoredProcedure
objDA.SelectCommand = sqlCmd
‘populate data table
objDA.Fill(DT)
‘bind data
DataList1.DataSource = DT.DefaultView
DataList1.DataBind()
‘disposing all the declared objects.
objDA.Dispose()
objDA = Nothing
sqlConn.Close()
sqlConn = Nothing
sqlCmd.Dispose()
sqlCmd.Connection.Close()
sqlCmd = Nothing
End If
End Sub
End Class  

Code for Detail WebPage. 

Create a folder named “Detail” and add one more Default.aspx webpage. Please follow the instructions.

In a Code Behind Just Copy Paste
Imports System.Data
Imports System.Data.SqlClient 

Partial Class Detail_Default
Inherits System.Web.UI.Page

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If Not IsPostBack Then 

 Dim sqlConn As New SqlConnection

 Dim sqlCmd As New SqlCommand(“PROC_TESTDETAIL” , sqlConn)
Dim objDA As New SqlDataAdapter

 Dim DT As New DataTable

‘Here you can specify your connection string.

 sqlConn.ConnectionString = ConfigurationManager.ConnectionStrings(

“connString” ).ConnectionString

‘opening a connection

sqlConn.Open()

sqlCmd.Connection = sqlConnsqlCmd.CommandType = CommandType.StoredProcedure

sqlCmd.Parameters.Add(“@ID”, SqlDbType.Int).Value = Request.QueryString(“ID” )
objDA.SelectCommand = sqlCmd

‘populate data table

objDA.Fill(DT)

‘bind data

lblTitle.Text = DT.Rows(0)(“Title” ) 

txtBody.Text = DT.Rows(0)(“Body” ) 

‘disposing all the declared objects.

objDA.Dispose()

objDA =Nothing

sqlConn.Close()

sqlConn =Nothing 

sqlCmd.Dispose()

sqlCmd.Connection.Close() 

sqlCmd =Nothing

End If
End Sub
End Class

Add Global.asax file in the project on the root

    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
        ‘ Code that runs on application startup
    End Sub
    Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
        ‘ Code that runs on application shutdown
    End Sub
    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        ‘ Code that runs when an unhandled error occurs
    End Sub
    Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
        ‘ Code that runs when a new session is started
    End Sub
    Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
        ‘ Code that runs when a session ends.
‘ Note: The Session_End event is raised only when the
‘ sessionstate mode
‘ is set to InProc in the Web.config file. If session
‘mode is set to StateServer?
 ‘ or SQLServer, the event is not raised.
    End Sub

 Protected Sub Application_BeginRequest(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim Old As String
    Dim MovingPath As String
    Dim IncomingURL As HttpContext
    Dim StartingIndex As Integer
    Dim ID As String
IncomingURL = HttpContext.Current
Old = IncomingURL.Request.Path
‘here you can filtered with if condition if you don’t
 want any directory to be caught and redirected some where
  If Regex.IsMatch(Old, “/Detail/”) Then
      Old = Old.Replace(“.ASPX”, “”)
      StartingIndex = Old.IndexOf(“~”)
      ID = Old.Remove(0, StartingIndex + 1)
      MovingPath = “~/Detail/Default.aspx?id=” + ID.ToString
      IncomingURL.RewritePath(MovingPath)
  End If
End Sub

In a web.config Add this key


Detail Page

 

.

 For complete article Please visit : http://blog.joggee.com/?p=182

Joggee, Is a Software Developer, Programmer, Database Administrator,having more than 8 years of extensive experience in difference languages specially Microsoft family.


Article from articlesbase.com



Be the first to comment - What do you think?
Posted by Anand Narayanaswamy - March 10, 2011 at 12:04 pm

Categories: ASP.NET   Tags: ASP.NET, project, Rewriting, Sample

Murach’s ADO.NET 3.5, LINQ, and the Entity Framework with C# 2008

Mike Murach & Associates has just published a new, C# edition of their popular ADO.NET book. Entitled Murach’s ADO.NET 3.5, LINQ, and the Entity Framework with C# 2008, it covers what today’s C# developer needs to know to create database applications the way the best professionals do. Here are some highlights:

#1: For rapid application development and prototyping…
This book shows how to use the ADO.NET tools, like data sources and the DataGridView control, that enable developers to create working database applications in a minimum of time, with a minimum of coding.

#2: For serious production applications…
This book shows how to go beyond the RAD tools, using heavy-duty ADO.NET coding and object data sources to build 3-layer applications that consist of presentation, business, and database classes.

#3: For incorporating LINQ into Windows and web applications…
This book has a 6-chapter section that’s a short course in LINQ, the .NET 3.5 feature that provides a consistent way to query different types of data. This section covers LINQ to Objects, LINQ to DataSet, LINQ to SQL, LINQ data source controls for web applications, and LINQ to XML.

#4: For database programming with the Entity Framework…
This book gets developers going with the Entity Framework, the .NET 3.5 feature that may change the way you do database programming. Entity Framework (EF) provides a flexible model for mapping the business objects in an application to database objects, and it generates a lot of the code that has to be written from scratch otherwise. A 4-chapter section shows how to create an Entity Data Model and work with it using LINQ to Entities, Entity SQL, and Entity data source controls for web applications.

#5: For training and reference: The "paired-pages" format…
This book uses Murach’s standard format to present the content in 2-page spreads, pairing a page of explanation with an illustrative page of syntax, screen shots, coding examples, and bulleted guidelines. Developers report that this lets them read less to get information faster, whether they use the book for training or reference.

Murach’s ADO.NET 3.5, LINQ, and the Entity Framework with C# 2008 is available directly from the publisher at www.murach.com and from all major retail outlets.

Murach’s ADO.NET 3.5, LINQ, and the Entity Framework with C# 2008
Author: Anne Boehm
Pages: 699   
ISBN: 978-1-890774-53-0
Price: $52.50

Be the first to comment - What do you think?
Posted by Anand Narayanaswamy - August 1, 2009 at 1:22 am

Categories: Latest, Press Releases   Tags: .tif silverlight visual basic, 978-1-890774-52-3 download, ado.net, ado.net 3.5. linq, ASP.NET, briefly about c# and c# tools, c sharp compiler download, c# compilers, C# keywords classified, csharp whiteboard, develop in c# in windows98, download C# compiler for windows xp, download different Types Of Compilers in C#, download ebook 978-1-890774-52-3, entity framework, explain briefly about c# and c# tools, google scada imaging, mike murach silverlight, multiform application in C#.Net, murach, murach silverlight, Murach Visual Studio 2010, murach's silverlight, project, sample DragLeave in c#, scada controls silverlight, silverlight shared whiteboard, toolbar of crystal report on vs 2010