ASP Tricks

ASP Tricks

Posted By: missionsix on Mar 06, 2005

Learn the some basic tricks to ASP coding

Okay, so you want to start learning ASP... and dont know where to start, or what to make? well ill show you some simple tricks that will allow you to create simple, yet effective ways of improving your site.


Tip #1: ASP INCLUDES

so you have a piece of code that you need have on more than one page and its exactly the same? why not use includes?

asp includes are very simple, and efficient if done correctly. To start of, you take the code you want on one or more page. and place it into a .txt document. From there, you rename hte file so its {filename}.INC (INC = include)

Next, on your asp pages.. all you type is:
Code:
<!--#INCLUDE FILE="file-name-of-include.inc" -->
one thing to remember: you cant start the location of an include with a forward slash so NO file="/skajfsld/aljdf.inc"

Tip #2: PASSING FORM INFORMATION

This tip will allow you to create a login, once you have set up a database or use a flat file to check it against.

Part one: The Form Itself

Okay, now for a login you neet three input values, one for the username, one for the password, and a Submit button.

To start off, create a new .asp document and add this code (or similar for the form)
HTML Code:
<form action="loginprocess.asp" method="post">
<input type="hidden" name="ipaddress"
 value="<%=request.ServerVariables("REMOTE_ADDR") %>">
<input type="text" name="username"> : username 

<input type="password" name="password"> : password
<br><br>
<input type="submit" value="Login"><br>
<a href="default.asp">Back to homepage?</a>
</form>
okay, now the first part of this form tells the browser where the form will go to, and if it will post the information to that page, or get (which adds the information to a string in the address bar).

the rest of it is pretty self explainatory.

Part 2: The FormProcess.asp page

now you will want to create a page name: formprocess.asp (or whatever name you made your form point to).

in this page you do not need any html code, it is all going to be asp based.

For the first part of this page, you want to retrieve all the information from the form.
To do this you simple create strings like this:
Code:
<%
strIP = request.form("ipaddress")
strUserName = request.form("username")
strPassword = request.form("password")
%>
All this code is doing is requesting the form variables and putting them into strings so we can use them.

Now we will want to see if they input any values and if they did not, return them to the login page.

We start off by using an IF statement, which means "if something is true, then do this"

Code:
If len(strusername) <1 OR len(strpassword) < 1  then
response.redirect("login.asp")
that is the basic syntax of the if statment, except for one important part, the ENDIF.. which closes it. But, we want to make it so if the length ( len() )of strusername is greater than 1, it will check the file. For this we use an ELSE statement.

Code:
If len(strusername) <1 OR len(strpassword) < 1  then

response.redirect("login.asp")

ELSE

{code for checking database } 

END IF
Okay, so now we have checked to see if they entered any values. now becuase they have we need to add code to the ELSE statement. Becuase i dont have that much time, im only going to use an inline login which there will only be one login name / combination to continue.

Code:
<%
If len(strusername) <1 OR len(strpassword) < 1  then

response.redirect("login.asp")

ELSE

   If strUserName = "admin" AND strPassword = "123" Then
      session("access") = 2
      response.redirect("secretpage.asp")
   End If

END IF
%>
Okay, so basically what i did was say if the login name and password are true, then add the session value of 2 and then redirect them to the "secretpage.asp".

The next step is to create a session check on the secret page, to restrict access.

Create a new .asp document called secretpage.asp. before the <html> tag add
Code:
<%
If session("access") > 1 Then
%>
Then at the bottom of the page after the closing </html> tag add
Code:
<%
Else
Response.redirect("login.asp")
End If
%>
That is, you have just created a SIMPLE login / access page.
to be continued when i have more time...
  • Comment on this tutorial
  • View the Printable Version

Posted On: Mar 06, 2005

Hits: 17449 - Unique: 15191

Advertise Here!

Quick Tutorial Search

VDC - Visual Design Core on Facebook

Our Popular Tutorials

Signature Backgrounds

Abstract Airbrushing

Rusty Metal Plate

Abstract Wave Technique

Cinema 4d Materials Tutorial

Abstract Renders in Cinema 4d

Dark Art Guide

Photoshop logo to Cinema 4d logo