Showing posts with label Web. Show all posts
Showing posts with label Web. Show all posts

Sunday, February 28, 2010

Earlier this week, I released a suite of Windows network troubleshooting utilities called Pinkie through a website named ipUptime.net.

Everything went well. The public seems to welcome it and as I monitor the statistics for the site as well as the download counts from other download sites, I realized that something is wrong with my site statistics; the numbers don't match up and my number came up short.

As I found out, if people download the Pinkie through the link on my site then the download count is incremented. But if they had download it from other sites, using the URL I had published then the download is not accounted for.

Changing the published URL for all other sites will be time consuming so I was looking for a better solution to the issue. Then I remember ASP.net 2.0 supports URL Mappings. So by using URL Mappings, within a minute or two, my problem is solved.

Here's the syntax for URL Mappings:

<urlmappings>
<add url="~/newurl.aspx" mappedurl="~/oldURL.aspx"></add>
</urlmappings>

Best use for URL Mappings are for shortening long, hard to remember URL to something short & easy to remember or in my case, correct a mistake and save time.

Friday, February 26, 2010

Simple Website

A friend of mine runs a small business in Houston, TX and needed to enhance the company's web image.

With the little free time I had, I was able to put together a simple, mostly static HTML site for her.

You can check it out here: eyecareforyouonline.com.

Thursday, February 25, 2010

Blogging again!!!

It's been a long while since I posted a blog. Well, apparently, I had forgotten my password and was unable to recover it since the email account I registered with Google wasn't active. Therefore, I wasn't able to login to the site.

In a recent Networking project called Pinkie, I needed to activate the web hosting account again and finally able to reset the password to the blogger account.

So in the comming days, I'll start blogging again when I get some free time.

Friday, January 18, 2008

Update Client Status on Long Running Job

Every once in a while I come across a question like: "I have a web application that has a long running job. It could take up to a few dozen minutes to complete. How can I keep the client status updated and not causing a timeout?"

The problem with a web application like this is that if the job run too long, it will cause a script timeout error. One can opt to increase the script timeout to prevent this but when you actually have an error, it would take forever before the client is notified of the error.

People often think that AJAX is the only solution to this problem but it isn't. But with a little clever coding, combining javascript with server side code, you can accomplish this. You can apply this technique to classic ASP or ASP.NET or whatever techonolgy or language you choose to use.

What we need to do is find a way to continuously sending data to the browser so that it doesn't time out on us. with vbscript and vb.net Repsonse.Buffer & Response.Flush can take care of this quite nicely.

So now we have the data streaming to the client, how to we update the status? The answer is javascript. We can script a function and take advantage of the ability to dynamically changing the content of the div or span tag to update the status when we receive some data from the server.

Please examine the source code for the complete example.

Monday, October 15, 2007

Using Enumerations To Document Your Code

Enumeration is a great way to assign easy to understand & remember textual names to your values. Consider the example:

Public Sub CityWork(ByVal CityID As Integer)
If CityID = 0 Then
'do something
ElseIf CityID = 1 Then
'do something
ElseIf CityID = 2 Then
'do something
Else
'do something
End If
End Sub

By the look of that, the code is pretty hard to understand as you have to remember what all those numbers are to associate with their function. To clarify things a bit, we can modify the above code using enumeration:

Public Enum CityTypes
SanDiego
SanFrancisco
SanJose
End Enum

Public Sub CityWork(ByVal CityID As CityTypes)
If CityID = CityTypes.SanDiego Then
'do something
ElseIf CityID = CityTypes.SanFrancisco Then
'do something
ElseIf CityID = CityTypes.SanJose Then
'do something
Else
'do something
End If
End Sub

Now this code is pretty much self-documented. It makes it so much easier to understand and will also allows you to take advantage of intellisense to help you code faster.

By default, the first enumerated value (SanDiego in this case) will have a value of 0. You can change that by explicitly assign an integer to it. The next enumerated value, if not specified, will be increased by 1 from the previous value (SanJose = 6)

Public Enum CityTypes
SanDiego = 1
SanFrancisco = 5
SanJose
End Enum

If you write your code this way, you'll find that it's much easier to understand, you can code faster, it's less prone to errors and at the same time, you pretty much self-documented the code.

Friday, October 12, 2007

Troubleshooting ASP.net Application with CustomErrors

There are many ways to troubleshoot IIS application errors. Here I will discuss a simple yet effective way to troubleshoot your IIS applications.

In the Web.config, under System.web node, there's one section called customErrors. By default this is commented out and the mode set to

<system.web>
<customerrors mode="RemoteOnly">
<system.web>


With this setting in place, if you run into some error, chances are you will only see a generic runtime error that reads:

An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.

In order to see what's going on, you will need to modify the Web.config file so the customErrors tag read:

<system.web>
<customerrors mode="Off">
<system.web>


Note that this should only be done on development workstations as the detailed error message could expose information you don't want users to see like identity impersonation information... As for production, try to run the application on the server to see the error.

Now that you can see what's actually causing the error, it should be easy to narrow the problem to a particular line number and take corrective action.

Thursday, October 11, 2007

Fixing Fail To Access IIS Metabase Error

I often run into this error message for various reasons like doing a reinstallation, machine upgrade or preparing a workstation for a new co-worker...

This error is fairly simple to fix but if you don't know how, it could drive one crazy. You often run into this error after you install Visual Studio 2005 and then try to run a webpage on your machine. The error you encounter will read something like this:

Failed to access IIS metabase.

If so, you may have installed IIS after the .NET framework has been installed. To fix this, try to repair your ASP.NET installation and set up all of the appropriate ISAPI extension mappings using the aspnet_regiss utility in the .NET framework folder.

aspnet_regiis -i

This utility is found in the .NET framework version number under your Windows installation folder.

Monday, August 13, 2007

Web Application Security

Web applications are at great risks due to the fact that most applications are widely available to anyone with internet access. They often get compromised by script exploits.

Most script exploits require the application to accept malicious input and inject it into a page where it will be executed on the server or in the client browser. The potential damage from such an exploit depends on the script that is being executed (taking over a system, install malware, deleting data...)

The primary defense against script exploit is to never trust the information obtained from users. This apply to both incoming and outgoing data from users (data written to and data pulled from database).

There are many things a developer can do to protect application against script exploits. Data input by users should always be validated. Form elements should be HTML-encoded. Dynamic SQL might be flexible but yet it can compromise your data. Consider parameterized query against SQL queries using string concatenation.

In this simple example:

"Select * From Customers where LastName = " & txtLastName.Value

A malicious user who knows a something about database could turn that SQL statement into:

Select * From Customers Where LastName = 'a'; Delete From Customers Where LastName > ''

And when it gets executed, the database is compromised.

It is very important to understand how users and their data interact with your application. That way you can better protect your data, application and users from script exploits.
For more information on how to protect your web application see Basic Security Practices for Web Applications.

How To Set Access Key For ASP.net Web Server Controls

Access key combination allows users to press ALT key plus another key to focus or jump to a specific control.

Some controls have Access property where you can set this like TextBox or ListBox. As an alternative, you can set an Access key for a Label control and then tell the browser to associate it with another control. With this approach, you can use the Label control as caption to indicate the access key with an underlined letter.

To set the access key using label control you must:

1. Add the control to be associated
2. Add a Label control
3. Set the access key
4. Associate the control to receive focus

Here's an example:

<asp:Label ID="lblLastName" runat="server"
AccessKey="L"
AssociatedControlID="txtLastName"
Text="<u>L</u>ast name: ">
</asp:Label>
<asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>


Note that setting focus by using access key from a Label control requires that client scripting is enabled in the browser.

Monday, July 16, 2007

Funky Name

I had a little time to spare and wanted to have some fun to relieve the stress so I created a little application that generate some funky names based on the user's input.

The name generation logic is based on a children's book, Captain Underpants And the Perilous Plot Professor Poopypants, by Dave Pilkey, in which the evil Professor forces everyone to assume new names...

The program uses some simple one dimensional arrays and use the user's input to index into the arrays and generate the new name. It also makes use of the one click deployment option.

Pretty funny. Give it a try.

The program can be downloaded from http://www.meshflowers.com/FunkyNames/

Thursday, June 21, 2007

Using Meta Tags

Web pages are only useful if you have people accessing them. People only come to your site if they know how to get to it. If your site isn't well established then you need to depend on search engines to advertise your pages to the rest of the world. One way of doing that is through the use of Meta Tags.

Most web developers are too focused on creating the page content, they often overlook Meta Tags. Here, I'll discuss some of the commonly used Meta tags.

Description Meta tag describes what the page or site is about. The syntax for this is:

<Meta Name="Description" Content="Page description">

Keywords Meta tag contains the keywords that would be relevant to the page/site. For example:

<Meta Name="Keywords" Content="Web, Programming, Blog">

Description & Keywords often go hand in hand. You could apply this at the site level (all pages have the same descriptions & keywords) or at the page level (all pages have different descriptions and keywords). I’ll talk more about this in search engine ranking blog.

Author Meta contains the name of the person who published the page:

<Meta Name="Author" Content="Brian Dao">

Revisit-After Meta tag tells the web crawlers or spiders to revisit the page after certain period has passed.

<Meta Name="Revisit-After" Content="7 days">

Robots Meta tag can instruct the crawlers to index the page and whether to follow the links found on the site or not:

<Meta Name="Robots" Content="index, follow">

These are just a few things you can do to help published your webpages and get them indexed with the search engines and not optimizing your site for better ranking in search engine index as I'll talk about that in another blog.

Wednesday, May 30, 2007

Basic SQL Syntax Troubleshooting

Developing dynamic web and/or desktop applications often involve querying the database for the desired data. One of the problems new programmers often run into is troubleshooting SQL syntax.

Here's a simple tip to help you troubleshoot your SQL syntax:

1. Write the SQL statement out to screen
2. Copy the SQL statement
3. Open the Access database
4. Create a new query
5. View the query text
6. Paste the SQL statement in the query window
7. Try to run the SQL statement

This should give you more info about the error you are running into.

But I am using SQL Server instead of Access database...

Don't worry, if you are running SQL Server or other databases, you can use Access and created linked tables to your database and take it from there.

Friday, May 25, 2007

Optimize Your Website For Performance

Performance can affect the number of visitors come to your site. The faster the site load, the better experience the visitors will get and the chances of them coming back will also be higher.

Network latency, congestion, packet drops... are already reducing your application performance. If you, the developer, can do anything to speed up content delivery, by all means, you should do it.

Unfortunately, most developers often neglect to pay attention to this are since it's not something they can really visually see and fix because there is no error that will popup and say "Hey, I am slow... fix me..." or something like that.

Here are a few tips that any developer can use to help speed up their web pages:

Put CSS code at the top of the page: if you put CSS at the top of the page, the browser will read it first. When the browser renders a web page, it doesn't have to search up and down looking for the style rules.

Move JavaScript code down to the bottom of the page: JavaScript’s are mostly run on the client side AFTER the page has been rendered. Moving them to the bottom of the page will allow the browser to render other markup tags first and present the UI to the client faster.

Compress java scripts & remove white space: The browser doesn't care if you name your function with a single character nor does it care if the name is 50 characters as long as they are valid. White spaces might make your code look good but will not help when it comes to speed. The less data your server has to spit out the faster your page will be delivered over the wire.

Remove duplicate and/or unused scripts: If it's not being used, remove it. If anything, it will cause more load on your network and create more confusion having it there when it comes time to troubleshoot some problems.

Do not mix Javascripts and HTML markups: Sometimes, you will need to use Javascripts to produce HTML markups. But try to reduce this to a minimum and let the browser finish one thing before it starts the next one (ie: complete HTML render before executing javascript...)

Move CSS & Javascripts out of HTML markups: Don't make the browser go back and forth between HTML markups and javascripts when it renders the page as there is a performance cost to this.

Add expires header: The browser save the pages onto the hard disk so that it can load the same site faster next time around. If there isn't a need for this, add expires header to it doesn't write the pages to disk.

Disable viewstates: ASP.net pages have viewstate enabled by default which adds a bunch of encrypted code to the page. If viewstate is not required, disable it and it will improve the page performance.
These tips will not significantly improve the performance of your web site as that will also depend upon how you compose your application but it will definitely improve the delivery of the page to the visitors. This is especially true if you have high traffic on your site.

If you get the opportunity, you should examine the HTML output for well known sites like Yahoo or Google and see how they optimize their site for performance. Chances are you will see these tips in action.

Monday, May 21, 2007

ViewState and Postback

I see a lot of people having problem preserving the controls's state when they perform postback. Most of these due to the fact they that don't quite understand how the form is processed on postback as seen in the following questions:

http://www.vbdotnetforums.com/showthread.php?t=18985
http://www.vbdotnetforums.com/showthread.php?t=19534

Have a look at this code snippet:

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

If Not IsPostBack Then

....

End If

LoadComboBoxes()

End Sub

IsPostBack will yield a True value if the page was posted back. You can use this to see whether this is the page load or refresh versus a post back and take appropriate action.

Let's say in the method LoadComboBoxes() you query the data from SQL and load that into the combo boxes. If you don't check for postback using IsPostBack, one of two things will happen:

1. If data binding is used on the controls or the Clear() method is called, all the state information gets wiped out and the controls will not retain their values.

2. If the Clear() method is not called then the combo boxes might have duplicate items added everytime you do a post back.

The recommended way for doing this is to move LoadComboBoxes inside the If statement that way it gets called once and also preserves postback data.

Sunday, May 20, 2007

Access IIS application from computers on the same network

A user was having problem accessing his website on the network. The site is working fine from the local machine. However, when he tries to access the same site from a computer on the network, it's not working.

The problem and attempted answers can be viewed in this post. You should read the posts in that forum before continuing on this blog so things would make sense when you read the paragraphs below.

Let's logically work through the posts and try to sort out the problems:

1. Setting up a new website, IP address and port number is not necessary as the original site already working on the machine IIS is running from. Since all the computers are on the same network, you should be able to access it by computer name as well.

2. On Win XP, you can actually host more than one sites and running more than one IP on the same computer. But this won't be discussed in this blog. On top of that, it's not even relevant to the problem we are trying to solve.

3. This shouldn't be security issue also since IIS applications typically run on anonymous account by default and permission is granted when the site is set up; unless you specifically make change to it.

The true answer to this lies in Windows XP Pro SP2's built-in Firewall. Open port 80 in Windows Firewall to allow web traffic should solve this issue. If there are other software firewall running, check and open port 80 as well.

Brian Dao

Thursday, May 17, 2007

Centering content on a web page

This is a very simple technique but if you take advantage of it, you could create very attractive web pages with it.

What you need to do is to create a table to wrap the content of your webpage in and set both the width and height properties of the table to "100%". For the horizontal alignment property of the cell, make it "center". You should also set the vertical property to "middle". By default, the browser will set this value to "middle" but it wouldn't hurt to explicitly set it yourself. If anything at all it would only make the code clearer and easier to understand.

Here's the sample code:

<table border="0" width="100%" height="100%">
<tr>
<td align="center" valign="middle">
Your content goes here.
</td>
</tr>
</table>


With this code in place, when you resize the browser, the table size will be updated and the content will be re-render to center it within the page.

Sunday, May 13, 2007

Create View Source Link

This blog will show you how to create a hyperlink on a Web page that displays the source code for the current page or another page when the hyperlink is clicked.

The normal Anchor tag when associate with the HREF parameter will cause the browser to pull the URL and display the page when the anchor link is clicked on. However, if you add the "view-source" prefix in front of the link, it will cause the browser to display the HTML source for the page instead of the rendered page itself.

Being able to display the source code of a web page is extremely valuable especially if you want to be able to show your site visitors how to do certain things or teach beginners how to compose HTML documents.

Keep in mind that "view-source" works only on absolute links. Also, if you are trying to access an HTML file through the FILE protocol, you must fully qualify the URL which means you have to include the full path to the file.

Here's the source code to create view source link:

<a href="view-source:http://yoursite.com/FileName.htm">Source Code</a>

Saturday, May 12, 2007

Redirect user to another pager after x seconds using Meta tag

In this blog you will learn how to redirect the users to another page/site after a number of seconds using meta tag.

Sometimes to be able to redirect your site visitors to another page automatically will come in handy, especially when you want to inform them that your site has been "moved" to a different URL so they can update their bookmarks.

To redirect the visitors to another page after a specified number of seconds, all you have to do is add the meta tag <META HTTP-EQUIV=" REFRESH" CONTENT="xxx; URL=newpage.htm"> to the header section of your page where xxx is the number of seconds to delay and newpage.htm is the URL of the page you want the visitors to go to.

Here's the code for it:

<html>
<head>
<META HTTP-EQUIV="REFRESH" CONTENT="3; URL=newpage.htm">
</head>
</html>


In this example, the browser will send the user to newpage.htm after 3 seconds.

Making a window focus - Javascript

At times, you will want to make a page active or re-gain focus after it has been loaded. You probably have seen a lot of these already while surfing the internet, especially from sites that has a lot of pop up ads.

One simple line of Javascript code window.focus(); will make the loading window gain focus. Alternatively, you might want to wait for the window to completely finish loading before you making it gain focus. To do so, simply add window.focus(); in the tag of the document along with the onload event.

Here's the code:

<HTML>
<Body onload="window.focus();">
</HTML>


Another way is to put the script at the very last line of code, just before tag as seen in the code below:

<HTML>
<Body>
...
...
<script language=javascript>
window.focus();
</script>
</Body>
</HTML>

Friday, May 11, 2007

Failed to access IIS metabase

I got a new laptop recently and tried to setup IIS and transfer existing sites to it. The laptop had typical Windows XP Pro setup with IIS 5.1, Visual Web Developer 2005 Express Edition and Microsoft .NET Framework 2.0 installed.

The sites were copied over and set to use ASP.NET version 2.0.50707 but when launched IIS generated the "Failed to access IIS metabase" error. Poking around on the internet I found some articles referring to things like granting permission to specific user accounts and re-registering ASP.NET... but none of these worked.

I even tried setting up a brand new website and still got the same problem. The only thing that worked was running the web apps as File System but that's not how I want it done.

While poking around with installed components (in Add/Remove Programs) and IIS settings, I suspected that the Microsoft .NET Framework 2.0 got corrupted so I reinstalled it.

Once the framework got repaired, all websites functioned the way they were supposed to. Hope this tip will help you solve problem.

Brian