How to get user name or user ip address?

Hi to all!

I have written a little survey application for our intranet. In order to prevent users from taking the survey a second (3rd, 4th, 5th...) time, the app should detect the user name, or the ip address of the session.
Does someone know how to manage this with WebMatrix? Thanks!
Bye,
Michael
To finish first, you first have to finish.
0
MP3Piranha
4/7/2004 5:53:59 AM
asp.net.getting-started 91979 articles. 3 followers. Follow

12 Replies
794 Views

Similar Articles

[PageSpeed] 6

Sure, you can use the Request object.

Request.UserHostAddress

Stanley Tan

theSpoke Blog
0
Stanley
4/7/2004 5:58:17 AM
Stanley,

thanks!
I searched the MSDN library. I found this article
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebHttpRequestClassUserHostAddressTopic.asp

Now i'm trying this:
<%@ Page Language="VB" Debug="true" %>
<%@ Register TagPrefix="wmx" Namespace="Microsoft.Matrix.Framework.Web.UI" Assembly="Microsoft.Matrix.Framework, Version=0.6.0.0, Culture=neutral, PublicKeyToken=6f763c9966660626" %>
<script runat="server">
Public ReadOnly Property UserHostAddress As String

dim ip as string
ip = Request.UserHostAddress

lblstatus.text = lblstatus.text & ip
I get an error message telling me: "Compilerfehlermeldung: BC30126: Die "ReadOnly"-Eigenschaft muss ein "Get" bereitstellen." -> "Compiler Error: BC30126: The "ReadOnly"-Property has to provide a "Get".
Thanks again for your help!
Bye,
Michael

To finish first, you first have to finish.
0
MP3Piranha
4/7/2004 6:21:49 AM
What line is the compiler balking on?
Stanley Tan

theSpoke Blog
0
Stanley
4/7/2004 6:24:59 AM
Line 5:

Zeile 3: <script runat="server">
Zeile 4:
-> Zeile 5: Public ReadOnly Property UserHostAddress As String <-
Zeile 6:
Zeile 7: dim ip as string
To finish first, you first have to finish.
0
MP3Piranha
4/7/2004 6:27:08 AM
Or, you can use this way to get the IP....


Dim sIPAddress
sIPAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If sIPAddress = "" Then sIPAddress = Request.ServerVariables("REMOTE_ADDR")

Zath
0
Zath
4/7/2004 6:31:51 AM
I'm not sure why you have that line in there.  Try deleting it if it's not necessary.
Stanley Tan

theSpoke Blog
0
Stanley
4/7/2004 6:43:27 AM
IF I delete the 'Public ReadOnly'' line, another error message appears:

Compiler Error Message: BC30188: Expected: Declaration
Source error:
Zeile 7: dim ip as string
Zeile 8:
Zeile 9: ip = Request.UserHostAddress
Zeile 10:
Zeile 11: lblstatus.text = lblstatus.text & ip

Source file: D:\WebMatrix\Umfrage\umfrage_accessdb.aspx Line: 9
(I've translated the necessary parts.)

To finish first, you first have to finish.
0
MP3Piranha
4/7/2004 6:49:22 AM
Zath,

thank you for your help. But it doesn't work, it results in the following error message:
Compiler Error : BC30188: Expected: Declaration
Source error:
Zeile 13: Dim sIPAddress
Zeile 14:
Zeile 15: sIPAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
Zeile 16:
Zeile 17: If sIPAddress = "" Then sIPAddress = Request.ServerVariables("REMOTE_ADDR")

Source file: D:\WebMatrix\Umfrage\umfrage_accessdb.aspx Line: 15
(I've translated the necessary parts.)
Bye,
Michael
To finish first, you first have to finish.
0
MP3Piranha
4/7/2004 6:52:46 AM
Zeile 13: Dim sIPAddress  --> Dim sIPAddress As String
Stanley Tan

theSpoke Blog
0
Stanley
4/7/2004 6:54:52 AM
Dim ipAddress As String = Request.UserHostAddress

Stanley Tan

theSpoke Blog
0
Stanley
4/7/2004 6:55:32 AM
Stanley,


got it! There was no

sub page_load
end sub

in the aspx file.
WebMatrix doesn't provide this VB.NET standard sub by default. Cutting&pasting your code in this sub made things work.
Source: http://it.maconstate.edu/tutorials/ASPNET/ASPNET02/aspnet02-06.aspx
It seems that I have to think more in my used Visual Basic 6 ways and to read a good book about VB.NET before getting in details with WebMatrix. :-)
Thanks again for your help!
Bye,
Michael
To finish first, you first have to finish.
0
MP3Piranha
4/7/2004 7:15:24 AM
Hi, great that you got it to work.  Note that if you double-click anywhere on the Web Form from within Web Matrix, it will automatically create this Page_Load event for you.  Good luck to you in your future projects.
Stanley Tan

theSpoke Blog
0
Stanley
4/7/2004 8:58:07 AM
Reply:

Similar Artilces:

Get the User Name for a login user
Hi Guys, How can I get the current loged in UserName in windows in MSSQL? The problem is: Users login into their PC (Windows Login) Enter a URL of the intranet application They would then be able to access the web base application (Intranet) The web application has a string connection to make a connection to the database I want to have a Trigger for my "products" table so if the table is modified (Insert/Update)  all those changes be entered in "products_Audit" table Now on "products_Audit" table I have a field "ChangedBy" where I want to store the windows loged...

get user name by user id
hi i send the user ID to a page and there i wanna find the user name. can you please let me know how to find a user name by user id? tanks  Are you using Active Directory? If so check out this tutorialCommunity Coder Hi you can pass the Guid USerId to Membership.GetUser method,MembershipUser usr = Membership.GetUser(UserIDAsGuid); string userName = usr.UserName; // to get the current logged in username , just use HttpContext.Current.User.Identity.Name;    Regards,Anas Ghanem.Note:Please Don't hesitate to click "Report Abuse" link if you noticed som...

Is it possible to get user name from active directory using IP address?
 Is it possible to get user name from active directory using IP address in .NET 2.0 code? So with the IP, you can find out the user name, then you know which user login using  the specific PC.A piece of demo code please.   Don't think that it is a good approach. If your application relies on windows authentication then you can get the domain user  Account by using this.User.Identity.Namewhere this is the instance of the page Jeev~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~If you get the answer to your question, please mark it as the answer. Using this.User.Identi...

Can not get user name from HttpContext.Current.User.Identity.Name
Hi All; I have tried to use HttpContext.Current.User.Identity.Name to get window user account. However, from debugger, for a long time ago I saw my window user name. But now, I did not see my window user name (from debugger) with the same code and same function call. Please help. Was I doing something wrong? Or any special settings on web.config/machine.config or project to make it work??? I'm stuck Thanks a lot well, you have to have windows integrated authentiction enabled in IIS, IIRC.RTFM - straight talk for web developers. Unmoderated, uncensored, occasionally unre...

Getting the user name of the currently logged in user
I'm writing my first custom module. Just as an experimental project I would just display information about the currently logged in user. I can get the User Id, but I don't know where to get the rest of the information. How do I get this? Hi, Just create a new UserController to get the information about one user via the method GetUser(PortalId, UserId) and store it into a UserInfo. Then you can get the rest of the information from this UserInfo [VB] Dim myUser As New UserInfo Dim myUserController As New UserController myUser = myUserController.GetUser(PortalId, Use...

Mining of a website to get the user names of its users
Hi, I have to do a application in which we have to trace  a website to get the user name of the uers in that website.Kindly give me idea or code to implement this.                                       Thanking you  If it's your website, I don't see why you would need to do this- you would know from the contents of your users database table. If it's not your own website, this is not c...

Problem in getting logged in user Name for ASPX page with (even with this.User.Identity.Name)
Hi  friends,  I am creating an application that takes current logged in user and displays on the page itself. for this I am getting the user name in PageLoad function by using this.User.Identity.Name and then storing the value in a hidden variable for aspx page. I am using this hidden  variable to display the name of the user. I am using Windows authentication for this. Now problem that I am getting is that when multiple user launch the application from different machine and if they click simultaneously, name of one user appears on the paged displayed on the machine of ot...

how to get the ip address of the user?
Now I want to save the user's informaion such as the ipaddress,the login time and so on,how to do?and how to show the online user list on the page? thanks for reply! request the ip address of the user Request.ServerVariables["REMOTE_ADDR"].ToString().Trim()-- Tough People Do Tough Task -- ...

Get users IP address
I need to modify the Send Thoughts module so that I will get the users public IP address. Can someone please provide some light on how I might accomplish this? You may be able accomplish what you want using the Request.Servervariables("REMOTE_ADDR") header. These may help:http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=577http://www.w3schools.com/asp/coll_servervariables.asp This link will be usefulhttp://www.vikramlakhotia.com/Post.aspx?postID=12Vikram www.vikramlakhotia.comPlease mark the answer if it helped you HttpContext.Current.Request.UserHostAddress; or...

Getting the users IP address
Ok here goes, I’m really new to ASP.net and just trying to get my head round all the objects and classes etc so please bear with me. I am trying to find out what IP address the user is from, to do this I’m using the class and then calling the variable from my page, when I type the following in the class it doesn’t have any problems but when I run the page it says  “Request is not available in this context” any ideas or can any one think of a better solution?  Public Class _Default    Inherits System.Web.UI.Page      Protected var_si...

Getting the IP address of a user
Is there an easy way to get a user's IP address if you know their username, either by a Novell tool or by the NDK/API? cogito.ergo.cogito@gmail.com wrote: > Is there an easy way to get a user's IP address if you know their > username, either by a Novell tool or by the NDK/API? Assuming they are logged into the server using IP nlist user=username /a/b -- -andy ...

Getting User My.User.Name to use in text box
Hi All,I have a page load event on my opening web page Default.aspx that includes the following code: SearchString = My.User.Name.ToString()when I run the code on my localhost it tells me that SearchString is (lets say) mashfield, my logged on user name.  However, when I i run it on our web server, searchstring returns blank.can anybody explain this?CheersMatt Matt A This means your request is not authenticated. User.Identity.Name is expected to be an empty string if the request is anonymous.If might want to disable the Anonymous access in InetMgr, at the application level. If Window...

How to get user name and user id from membership cookie
Hello,Is there any way to get the users logged users name and user id from the login cookie? I am using asp.net membership class. And also wanted to know if GetUserName() calls the database when ever it is called? thanks for any commentslistsergeant.com public static String GetUserName (HttpContext context) {    return context.User.Identity.Name;  } Try this K.Mohamed Faizal Solution Architecthttp://faizal-comeacross.blogspot.comPlease remember to click "Mark as Answer" on this post if it helped you Let say if you want to get Windows username then make sure...

how to get the user group name by HttpContext.Current.User?
Is it possible to get the domain user group name or role name on domain server by HttpContext.Current.User?For example, I want to identify if the user belongs to group myDomain/Administrators, I try to use User.IsInRole("myDomain/Administrators"), but I failed.One user maybe join multiple groups. How to get the all groups in code for current user?  Demo code for C# and VB please.   Try using this instead: VB: If Page.User.IsInRole("DOMAIN\GROUPNAME") C# If Page.User.IsInRole("DOMAIN\\GROUPNAME") Note, this will only work if you have ...

Web resources about - How to get user name or user ip address? - asp.net.getting-started

IPv4 address exhaustion - Wikipedia, the free encyclopedia
IPv4 address exhaustion is the depletion of the pool of unallocated Internet Protocol Version 4 (IPv4) addresses. The IP address space is managed ...

Outlook online to get a better address book and flight confirmations
... needs extras that attract customers to its offering. Now the company is announcing a couple of updates including improvements to the address ...

"After months of hype, it looks like one of this year’s biggest flops is Addyi, the little pink pill ...
"The libido drug — which must be taken daily and has such severe potential side effects that women are told not to drink while on it — has been ...

Clinton must choose how to address data breach in Dem debate
The question facing Hillary Clinton is how forcefully to confront Bernie Sanders about the actions of his campaign staff.

GOP Establishment Has No Problem with Hillary Win, Won’t Address the Clintons’ War on Women
Breitbart News' John Nolte had a perceptive piece this weekend on the GOP Establishment having no desire to beat Hillary Clinton or elect Donald ...

​Hillary Clinton to address homegrown terror threat
Democratic front-runner will speak in Minneapolis Tuesday afternoon

Clinton to address terror protection
As domestic terror fears rise, Hillary Clinton is set to explain how she will protect Americans, reports NBC News.

Obama Talks Christian Values In Christmas Address
'That’s the spirit that binds us together – not just as Christians, but as Americans of all faiths'

Obama gets 'in on the action' with top 10 list in his weekly address
... my top 10 things that happened in 2015 that should make every American optimistic about 2016 President Obama, in a light-hearted weekly address ...

Congress Shockingly Fails to Address Alleged EPA Lawbreaking
Right now, the EPA is making Congress look foolish.

Resources last updated: 12/31/2015 11:56:31 AM