Discussion Locked

VBScript Error handling

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I am writing a site using ASP 3.0 pages and VBScript. I am connecting to a SQL Server 2k database and running on a Windows 2k IIS server.
I am using Windows security to log people in but need to know how to capture if a user hasn't got permission to the database and show an error page telling them they do not have permissions. I need to do this in the VBScript. How do I go about this?

6 replies

by lukcad

I am using ASP.NET technology but I was early ASP programmer too, may be it helps for you:

<%@ LANGUAGE = VBScript %>
<% Option Explicit %>

<%
'Force Authentication if the LOGON_USER Server Variable is blank
'by sending the Response.Status of 401 Access Denied.

'Finish the Page by issuing a Response.End so that a user
'cannot cancel through the dialog box.

If Request.ServerVariables("LOGON_USER") = "" Then
Response.Status = "401 Access Denied"
Response.End
End If
%>

Login Screens

Login Screens


You logged in as user: <%= Request.ServerVariables("LOGON_USER") %>

You were authenticated using: <%= Request.ServerVariables("AUTH_TYPE") %> authentication.

by lukcad

it's too hard to uderstand, if you would like another way for checking permission of user and sending special message for him, you can simply use the possability of IIS identification. I hope that you know that are three ways: form, IIS and Windows Authentication. You can send me your letter and I can propouse myself manner for that - another from traditional bat also smart.

by adasys

here is what you have to do.
Use a testuser as your userid in windows and create one in your sql but dont have right to the database.
Access the page you created and of course you will have an erro. Whis is an asp error or Transatsql error. Remember the error number. then rewrite you code with the ff. line inserted.

<%
on error resume next
this line or pff. lines your code to access the sql

if err.number = this is the number a while ago then
Response.Write("No Access")
end if

%>

by munrrob

Thanks for all the ideas but I was able to find the code I needed:

if objConn.State=adStateClosed then
Response.Redirect "./Error.asp"
end if

This works perfectly well when tested..

This discussion is closed to new replies.