Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Logon_User will not pass into Dll

Status
Not open for further replies.

HebieBug

Programmer
Jan 8, 2001
354
JP
Having some problems with the Logon_User. I can display the users logon on the page. What I am really after is a situation where the username is passed into a dll and then taken out of the format of domain\Hebiebug. It will then become HebieBug. It also passes the username into another dll so that the dll can run a SQL Query based on the username. So I started by seeing if I could get the username into a variable the code that I came up with was
<SCRIPT LANGUAGE=VBSCRIPT>
sub clicked
dim peter
peter = Request.ServerVariables(&quot;LOGON_USER&quot;)
msgbox peter
end sub
</SCRIPT>
Unfortunatly the books don't cover this area and I think it might have something to do with the security side of things. Could someone confirm this or come up with the correct code?

 
There is a problem with the code snipet you included. Your subroutine is in client side script, but you are attempting to access a Server side variable. This won't work.

I'm assuming your DLL is on the server, so you won't need any client code. You could have a function in your DLL that accepts the LOGON_USER and returns the username with the server/ cut off.

Function Truncate_UserName(UserID as String) as String
Dim intPos
'find the slash
intPos = InStr(UserID, &quot;/&quot;)
If intPos > 0 Then
Truncate_UserName = Mid(UserID, intPos + 1)
End If
End Function

You would probably want to add a check to ensure a valid server/username is passed in.

Now your ASP page could pass the LOGON_USER variable and get the user name back from the DLL.

Set objDLL = Server.CreateObject(&quot;DLL NAME&quot;)
strLogonUser = Request.ServerVariables(&quot;LOGON_USER&quot;)
strUserName = objDLL.Truncate_UserName(CStr(strLogonUser))
Set objDLL = Nothing

If you need further assistance, please let me know.

Good Luck!
Rich
 
I see what your saying and it makes sence.
Just to confirm so I do't make the same mistake again.
If the ASP is loading then it will accept server side script but once it has loaded and I get it to do a onclick or another user command it will only load client side scripts.
If that's the case is there such a thing as a variable that one would dim at the start of the asp loading and then put the username in. Then onclick it could display the variable.
Am asking this to get a better understanding of how ASP works.
The best place to get the answers is from people like yourself who have greater experience on the study.
 
Code wrapped in the <script language=vbscript> and </script> tags are considered client side. The Request object, which contains the ServerVariables collection, and is housed on the Server, cannot be accessed from client side code - at least not directly. Your client code can be thought of as code that responds to client input, like responding to a button click. Server side code will be responsible for receiving data from the client and passing it to any DLL functions or procedures.

This is just a start when it comes to ASP...you may want to check out other ASP help sites for additional assistance (like ASPToday.com).

Good Luck.
Rich
 
It is an amazing peice of technology. I am very interested in learning more on the subject. Have been working with VB for the past year and a half and it's a joy to know that the learning process incorporates what I have already learnt. The best part of this internet boom is the fact that we all can obtain the information at any hour of the day or night and the network of programmers who are there to help each other through the query stages.
 
Have tried out the code that you supplied in brief
1. Created DLL and added code set MTSTransactionmode to 2-requires Transaction
2. Made dll.
3. Added to Comm+ and set it to required
4. Made the ASP page
Snippit provided below:
<body>
<%
Set objDLL = Server.CreateObject(&quot;UserName.Access&quot;)
strLogonUser = Request.ServerVariables(&quot;LOGON_USER&quot;)
strUserName = objDLL.Truncate_UserName(CStr(strLogonUser))
Set objDLL = Nothing
%>
<p>
Your account name is <%=strUserName%>
</p>
<BR />
</body>
For some odd reason it does not fill the variable and returns nothing. Any more ideas on what I am missing on the subject
Annonomis login has been turned off..
 
Keep in mind here that I am using VB 6.0, Windows NT, IIS 4.0, and ASP 2.0. If you're using other technology, there may be something that I'm missing.

Here's another thing I've learned...the hard way...debugging ASP is a real pain. I would try this...

Set objDLL = Server.CreateObject(&quot;UserName.Access&quot;)
If Err.Number > 0 Then
Set objDLL = Nothing
Response.Write &quot;Error creating UserName.Access object&quot;
Response.End
End If
(This checks to ensure the object is created without error - You can leave this check in there for good error handling).

strLogonUser = Request.ServerVariables(&quot;LOGON_USER&quot;)
Response.Write &quot;LOGON_USER: &quot; & strLogonUser
Response.End
(This ensures that you're getting the ServerVariable - this is just debugging code and should be removed once you verify the value).

strUserName = objDLL.Truncate_UserName(CStr(strLogonUser))
If Err.Number > 0 Then
Set objDLL = Nothing
Response.Write &quot;Error in Truncate_UserName function.&quot;
Response.End
End If
(This checks to ensure the function worked without error - You can leave this check in there for good error handling).

If you don't get error messages and you verify that the LOGON_USER variable is what it should be, you may want to go over your DLL's Truncate_UserName function.

Rich
 
Tested the VB code by inserting code from dll into a module and calling on it from a form.
No problem with it at all.
Then I gave the ASP code that you provided in last thread. It works fine it comes up with the domain\hebiebug response.
It seems the problem is bringing the returned variable back from the DLL..
If I created a variable in the DLL say it was called ReturnedUserName is there a way of calling apon that variable to be returned into the asp?
If I can check that out then we may just have an answer on the situation
Also running
2000 server
IIS
ASP 2.0
 
The variable strUserName (on the ASP) should have the value returned by the DLL's function (Truncate_UserName). Did you set it up in the DLL as a function?
 
Yes,
It is set as a function. I copied the code that you kindly provided to me.
I have been creating other Dll's that query the database based upon a criteria. They work just perfectly. The only area that I am becoming unstuck in is this passing of username. It is going to be used to display the username in one asp page and then it is going to query the database and show them every client that they have outstanding.
If you would like and have the time I could send you my VB app and the asp page to confirm that I am doing it correctly.
My email address is Henrymaher@yahoo.co.uk
 
Rich I have the answer to it:
it's only one character that is causing the no response back.
&quot;\&quot; insteed we where using &quot;/&quot;
Case closed on this one. Fantastic of you to help me through it. Will you help you have cleared up much of my quesitons on the study of ASP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top