Jack is Here, asp.net findings

As a software engineer, I focus on .NET, especially asp.net, C#, WCF and so on, and I am also very interested in Search Engine Optimization.

Entries Tagged ‘web request’

FIX: You receive an exception error message when you specify a Content-Length HTTP header that is larger than 2 GB in ASP.NET 2.0

Symptoms
In Microsoft ASP.NET 2.0, when you try to use the TransmitFile function to specify a Content-Length HTTP header that is larger than 2 gigabytes (GB), you receive the following exception error message:

Value was either too large or too small for an Int32. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.OverflowException: Value was either too large or too small for an Int32. Additionally, you may experience a problem with application pool restarts under a heavy load. This problem can cause a decrease in performance on a server that is running Microsoft Internet Information Services (IIS) and an ASP.NET Web application.
Resolution
This problem occurs when ASP.NET 2.0 tries to parse the value of the Content-Length HTTP header as an Int32 data type. Therefore, if the value of the header is more than the maximum value of an Int32 data type, an overflow exception occurs. The maximum value of an Int32 data type is 2,147,483,647.

Url Rewriting in Asp.net With Sample Project

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

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

I have a few minutes, to learn how to achieve URL rewriting, I'll be in a simple example, in this article.

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 the default Web page to write the following code. I pasted the complete code for the default page. Where do I direct use of DataList, there are two areas of binding.

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, e ByVal As System.EventArgs) Me Handles

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's"). The 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

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