(Updated to correct some code which is correct in the download but not correct in the Article. Copy and paste is your enemy at times.)
Using [ASP.NET][C#] Version, we will look up the US Zip Code to find any zip code in the US in this easy-to-use code. In this example, we will be using [ASP.NET (C#)].
Live Lessons Example - ASP.NET (C# Version) check if Zip Code exists. If not, show a message.
When the user enters their Zip Code into the form, we will do the following.
(Protecting our Database from XSS Attacks) Date: 07-30-2022 - Name changed of Function from ProtectSQL to ProtectXSS, as it was brought to my attention that saying SQL was misleading.
Use a function that will protect our database from [XSS] attacks called: [ProtectXSS]
Validate the form value against our database.
Protect our Database from [SQL injection] using [Parameterized Queries].
If the Zip Code [Does exist], we will display a message to the user, letting them know that the Zip Code exists
If the ZIP Code [Does not exist], we will display a message indicating it does not exist.
[Section #3:] To protect ourselves from SQL Injections, we need to use [Parameterized Queries]. The following unsafe query was rapidly available when I first started learning ASP Classic.
(You can find examples of this poor code all over forums dating back to the late 90s and 2000s.
SqlCommand getZip = new SqlCommand("select Zip, City, State, County from ZipTable where Zip=@Zip", LessonCon);
getZip.Parameters.Add(new SqlParameter("@Zip", ZC));