How to uniquely identify the client machine in an ASP.NET application?
I have a server application that runs in a hosted environment but creates print j开发者_如何学JAVAobs in the client's local network (behind NAT; the mechanics of this is not relevant).
In order to send the print job to the printer that is attached to the workstation, I need to identify the workstation. The users move around between workstations, so I can't permanently associate a user with a workstation/printer. The trivial solution is to require the user to identify the machine he is logging in from, for instance by selecting from a list, but that's an inconvenience and subject to user error.
Options I have eliminated:
- Host header variables (nothing identifiable is sent)
- Cookies, in support of a user selection. This somewhat addresses the potential for user error, but not really.
- HTML5 DOM Storage - is not supported by the client's browser
Any other ideas?
Edit: I do have the option of puttnig this particular function (create a print job) into a thick client app. The app can then of course be configured and the problem goes away. But the user experience will suffer from having to switch between the browser and a Windows app.
I won't discuss your strange scenario, just answer your question: how to identify a machine?
Well, there is no close-form solution at current time with HTTP protocol. All machines share the same IP since they are behind NAT. You can't get MAC address. You can't get hardware identifiers. You can't be sure that all machine will send different headers to the server (ie. all different browsers/version).
You may rely on cookies. Try to create some form of machine authentication, or better, machine identification page, browse it once from each machine telling the server which is the printer to use on that machine, and then set a permanent cookie on that machine.
As soon as cookies won't be deleted (maybe you can always renew the cookie, you never know...) you have a simple mechanism.
It's the best I can suggest :(
If you look up the servervariables when they make a request you will have Request.ServerVariables["REMOTE_ADDR"]; which would probably be the internal IP if the app is internal/intranet. There is also REMOTE_HOST. Sometimes these are filtered off by proxies/firewalls/nat but hopefully not in your situation.
You can also call these on the HTTPRequest object like Request.UserHostAddress. You might need to get it by the current context HTTPContext.Current.Request.UserHostAddress.
If you can't get that then just return the document, data, file to the Request to have them print and choose their printer via Response.BinaryWrite() setting the content type of the file they are accessing.
All servervariables are listed here for IIS since you are using ASP.NET: http://msdn.microsoft.com/en-us/library/ms524602(v=vs.90).aspx
Another possibility is to email it to the user if it is a long running report or allow them to access the document with a log-in to print themselves.
If REMOTE_ADDR is actually working as advertised, have you tried it's brother, REMOTE_HOST? If HOST doesn’t work, but ADDR does, then
RemoteHostOughta = GetHostEntry(Request.ServerVariables("REMOTE_ADDR")).HostName
Unfortunately, there is some setting I don’t know about such that my IIS is getting the server IP (not a router!) instead of the remote when I read REMOTE_ADDR
精彩评论