aRo` automating your e-commerce

This blog has been neglected due to the success of Solidshops.com
24Feb/06

Using form authentication in asp.net

Instead of writing your own code for checking if a user has access to a page just use the formauthentication that is available to u :)

web.config (mind the ‘ )

<'authentication mode="Forms">
<'forms name="appNameAuth" path="/" loginUrl="login.aspx" protection="All" timeout="30">
<'credentials passwordFormat="Clear">
<'user name="user" password="password" />
<'/credentials>
<'/forms>
<'/authentication>

login.aspx

<%@Import Namespace="System.Web.Security" %>
‘Sub ProcessLogin(objSender As Object, objArgs As EventArgs)

If FormsAuthentication.Authenticate(txtUser.Text, txtPassword.Text) Then
FormsAuthentication.RedirectFromLoginPage(txtUser.Text, chkPersistLogin.Checked)
Else
ErrorMessage.InnerHtml = “Something went wrong… please re-enter your credentials…”
End If

End Sub

Page.aspx

<%@Import Namespace="System.Web.Security" %>
Sub SignOut(objSender As Object, objArgs As EventArgs)
‘delete the users auth cookie and sign out
FormsAuthentication.SignOut()
‘redirect the user to their referring page
Response.Redirect(Request.UrlReferrer.ToString())
End Sub
Sub Page_Load()
‘verify authentication
If User.Identity.IsAuthenticated Then
‘display Credential information
displayCredentials.InnerHtml = “Current User : ” & User.Identity.Name & “” & _

Authentication Used : ” & User.Identity.AuthenticationType & “
Else
‘Display Error Message
displayCredentials.InnerHtml = “Sorry, you have not been authenticated.”
End If
End Sub

Popularity: 1% [?]

Filed under: asp.net No Comments
22Feb/06

Create a function simular to the iif access function

The access function iif is very easy to check an expression and return a different value wether the expression is true or false.


function iif($expression, $returntrue, $returnfalse = '') {
    return (
$expression ? $returntrue : $returnfalse);
}
?>

Popularity: 1% [?]

Filed under: php No Comments
22Feb/06

Calling a Vbscript msgbox using Javascript

Javascript just offers a simple alert box without any customisation. With the code below u can call a VBscript function from javascript witch makes it possible to create your own alert box with or without an icon.
Javascript function

NS4 = (document.layers);
IE4 = (document.all);
ver4 = (NS4 || IE4);

function newAlert(title,mess,icon,mods) {
(IE4) ? makeMsgBox(title,mess,icon,0,0,mods) : alert(mess);
}

VBScript function

Function makeMsgBox(tit,mess,icons,buts,defs,mods)
butVal = buts + (icons*16) + (defs*256) + (mods*4096)
makeMsgBox = MsgBox(mess,butVal,tit)
End Function

Call the new alert box

newAlert(“title”,”msg”,0,0);

Popularity: 2% [?]

Filed under: javascript 1 Comment
19Feb/06

Working with data from access database in asp.net

Connection to Access Database

Imports System.Data.OleDb
Private Const strConnection As String = “Provider=Microsoft.Jet.OLEDB.4.0; Data Source=db.mdb;
Private objConnection As OleDbConnection = New OleDbConnection(strConnection)
Try
objConnection.Open()
….
objConnection.Close()
Catch myException As System.Exception
MessageBox.Show(myException.Message)
End Try

Command – ExecuteNonQuery UPDATE / DELETE / INSERT

Dim strSQL As String = “Insert into tblX (X ,Y) values (valueX,valueY)”
Dim objCommand As OleDbCommand = New OleDbCommand(strSQL, objConnection)
objCommand.ExecuteNonQuery()

Command – ExecuteScalar SELECT

Dim strSQL As String = “Select count(*) from tblFabrieken”
Dim objCommand As OleDbCommand = New OleDbCommand(strSQL, objConnection)
Dim intNumber As Integer
intNumber = objCommand.ExecuteScalar()

Command – ExecuteReader – DataReader (Read forward only cursor)

Dim objCommand As OleDbCommand = New OleDbCommand(“Select * from tblFabrieken”, objConnection)
Dim objReader As OleDbDataReader
objReader = objCommand.ExecuteReader()

Do While objReader.Read()
MsgBox(objReader(“Naam”))
Loop

objReader.Close()

Popularity: 1% [?]

Filed under: asp.net No Comments
6Feb/06

Connection to access or MS SQL database in ASP

The best way of connecting to a database is including a separated file with the database info. Afterwards u can always check if the database connection state is open.

MS SQL
set cnn = Server.CreateObject(“ADODB.Connection”)
cnn.ConnectionString = “Provider=SQLOLEDB.1;User ID=User;Passwd=;Initial Catalog=ASPDB;Data Source=server”
cnn.Open

Microsoft Access
set cnn = Server.CreateObject(“ADODB.Connection”)
cnn.Provider = “Microsoft.Jet.OLEDB.4.0″
cnn.ConnectionString = Server.MapPath (“/mywwwfolder”) & “\database.mdb”
cnn.Open

check connection state
if cnn.State = 0 then
cnn.Open
end if

Popularity: 3% [?]

Filed under: asp No Comments