labs.insert-title.com

ASP to ASP.NET III

This article documents work done on Insert Title Web Designs

XML.ASP

At the heart of our website is this single file/script which calls all other pages and allows us to incorporate new pages into our site without a lot of revamping or reconfiguring.

This file was discussed in Part 1 of the article and here is what I did.

From the original code below:


<%
Set xml = Server.CreateObject("Microsoft.XMLHTTP")

	dim URL,page
	URL = "http://www.insert-title.com/web_design/"
	page = request.querystring("page")
		if page = "" then
			page = "dcontent"
		end if

	dim ext
	if left(page,9) = "articles/" then
		ext = ".html"
	else
		ext = ".asp"
	end if
Set fso = CreateObject("Scripting.FileSystemObject")
if fso.FileExists ("FULL PATH TO THE FILE" & replace(page,"/","\") & ext) then
	xml.Open "GET", URL & page & ext, False
	xml.Send
	Response.Write xml.responseText
else
	response.write "Page not found, sorry"
end if
Set xml = Nothing
%>

I created the following


<%@ Control Language="vb"%>
<%@ Import Namespace="System.Net" %>
<script language="VB" runat="server">
Sub Page_Load(sender as Object, e as EventArgs)
   Dim objWebClient as New WebClient()
   Dim page as String
   Dim ext as String
   Dim objStringBuild as StringBuilder
   page = Request.QueryString("page")
      if page = "" then
         page = "dcontent"
      end if


      if page.IndexOf( "articles/" ) > 0 then
         ext = ( ".html" )
      else
         ext = ( ".asp" )
      end if


   objStringBuild = New StringBuilder ("http://www.insert-title.com/web_design/")
   objStringBuild.Append (page)
   objStringBuild.Append (ext)

   Dim strURL as String
   strURL = objStringBuild.ToString()
   Dim objUTF8 as New UTF8Encoding()
   responsetext.Text = objUTF8.GetString(objWebClient.DownloadData(strURL))
End Sub
</script>
<asp:label id="responsetext" runat="server" />

I also updated the default.aspx file to include the new xml.ascx (formerly xml.asp) user control to read


<%@ Page Trace=False Language="vb" %>
<%@ Register TagPrefix="oo" TagName="Open" Src="open.ascx" %>
<%@ Register TagPrefix="xx" TagName="XML" Src="xml.ascx" %>
<%@ Register TagPrefix="cc" TagName="Close" Src="close.ascx" %>
<oo:Open id="Open" runat="server" <>/oo:Open>
<xx:XML id="XML" runat="server" <>/xx:XML>
<cc:Close id="close" runat="server" <>/cc:Close>

What I did

Based on two articles I read, one from 4guysfromrolla.com, ASP.NET Unleashed (c/o Dan Kirkwood Jr. of Eagle Innovations). I was able to develop the new code. One thing to note is that there doesn't seem to be a lot of support when it comes to String Manipulation in ASP.NET available on the web, so I did have to turn to the book for that, which I must say seems to be the best reference for this feature as of yet.

So, essentially, I removed the "XMLHTTPObject" and began working with the "WebClient()" class.

I used the "StringBuilder" class to add my desired extension to the "strURL" creating


http://www.insert-title.com/web_design/default.asp?page=articles/jtops.html

from


"?page=articles/jtops"

One thing I have not yet handled was the "File Not Found" issue, this was originall handled with ASP Classics FileSystem Objectr, I will have to find a solution to this before all is done.

At first this class for building up a string seemed a bit alien to me, but after using it a bit, it isn't really all that different from what you may have already done in classic ASP


str = "abcdefgh"
str = str + "ijklmnopqrs"
str = str + "tuvwxyz
response.write str

BECOMES


<%@ Import Namespace="System.Net" %>
<script language="VB" runat="server">
Sub Page_Load(s as Object, e as EventArgs)

    Dim str as StringBuilder

	str = New StringBuilder ("abcdefgh")
	str.Append ("ijklmnopqrs")
	str.Append ("tuvwxyz")

	Dim strText as String = str.ToString()
	myText.Text = strText
End Sub
</script>
<asp:label id="myText" runat="server" />

Another issue I ran across was the lack of support of the ASP Classic function "Instr"

Where this would have worked in Classic ASP


dim ext
if inStr(page,"articles/") > 0 then
	ext = ".html"
else
	ext = ".asp"
end if

I now had to use:


if page.IndexOf( "articles/" ) > 0 then
         ext = ( ".html" )
      else
         ext = ( ".asp" )
      end if

Not a huge difference, but we still seem to be lacking in documentation about these string manipulation features for .NET

Next Task: Converting some of the dynamic applications on the site from ASP Classic to ASP.NET






Discussion

hadi

I want to reverse single dimension array in vb.net

dim str as string = "abcdefgh"

how can I access its each element like str(0) that is a and so on...I encountered error...plz tell

New comments are currently disabled, you can find me @joemaddalone Comments temporarily disabled for now, you can find me @joemaddalone