With the command prompt it is possible to query the sessions for a server, as shown here (https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/query-session).
With an aspx file you can get a unique sessin ID by using:
System.Web.HttpContext.Current.Session.SessionID
Also, with an aspx file you can get the IP address by using:
Request.UserHostAddress
Is it possible with an aspx file to obtain the session name (e.g. console, rdp-tcp#10) and the corresponding ID number (integer)? I am trying to integrate an old piece of software that records a terminal/server ID number as part of key to record a user's request in a database.
Background:
I have a file with the extension .aspx from around ~2011 that integrates an enterprise database with software delivered by a web browser (software as a service?). This file contains a call to Request["sessionId"] which I don't think returns anything as the key "sessionId" may nolonger be supportted? For the file logic, all I need to know is whether the user has the "console" session type or not. This aspx file is called by a batch file whenever a user presses one of the buttons on the enterprise database.
Related
I have a SignalR Chat that is available to anonymous users. I need a way to map the users so that the connections persist on page reload, and if the user has multiple tabs they should get the message displayed on every tab.
If I use Context.ConnectionId, every page reload creates a new connection. I want to map these connections using Single-user groups.
For logged-in users, I use Context.User.Identity.Name:
Groups.AddAsync(Context.ConnectionId, Context.User.Identity.Name);
Is there a similar way to get an anonymous user's "identity"? From what I have read, session is not supposed to be used in the SignalR hub, but all the information I found is old, so I may be wrong here.
When you reload a page the existing connection will be closed and a new one will be opened. The new connection will have a new connection id and on the server side you will not be able to tell what user initiated it. Depending on your circumstances you could try identifying the user by their ip addresses - i.e. you would store the user ip when the connection is open and then, when a new connection is opened you would check if you have already seen the ip. This may not work however because the same user can actually have different ips and multiple users can have the same ip. Another method would be to send a client side generated identifier in the query string when opening the connection and use that to identify the same user on the server side.
You must implement some mechanism to create unique ID for each user.
I would do something like following
Before user actually connects to Hub i would create a unique ID and
store it in cookie
set the query string for signalR URL with the value of this cookie so
that each call to hub will avail with the user's ID
now even when the user refreshes the page, the old connection would
automatically get removed from the group by signalR and you can
continue adding new connections mapped against the uniquely generated
ID.
I am building a method that will build an XLS file and uploading it on user's computer.
I am using this guide:
http://csharp.net-informations.com/excel/csharp-create-excel.htm
So code that will define my destination address is:
xlWorkBook.SaveAs("C:\\Something\\csharp-Excel.xls", Excel.XlFileFormat.xlWorkbookNormal);
Now it is default, but i want to allow user to define it by him self, so as far as i understand, i need an html field, which will open common "browse window" and save file path to string, which will be later used in xlWorkBook.SaveAs function. I have read a bit about FileUpload, but i don't really sure that it is what i am looking for.
The code that you have there will save the file on the web server itself, not on the user's computer. You'll need to stream the file down to the user via the browser, and then they will be able to choose where to save it.
You could save the file on the server and then stream it to the user using Response.WriteFile, or you could stream it from memory if you don't want to keep a copy of the file on the server.
This code will create a file on the server, not on the users/clients computer. If you want the user to be able to download the file to his/her computer and select the location where the file is stored, you need to create a file (.aspx file or controller method, depending on wether you are using webforms or MVC) and have it stream the file to the user's browser. The browser will then take care of displaying the "Save as" dialog where the user can select the destination location.
I built an c# desktop application for attendance
application is working fine when i run it on single machine and all is good..
but now issue is ... my boss want this application should work on LAN and every client can access application from server
but i used static variables which store some values at run time and then i utilized these values in next forms.
here is example..
on login form username is stored in static variable as
public static string username;
username = txtUser.Text.Trim().ToString();
and in next form which is Home Page this user name is used as
lblName.Text = Login.username;
here lblName is name of label and Login name of Login form
when i configure this application on LAN then may be at same time more than one user will be logged in and want to access application then each user should see his/her own username....
e-g abc is user 1 and xyz is user 2
if both are logged in at same time then i want abc to see
lblName.Text = "abc"
and xyz to see
lblName.Text = "xyz"
so what should i do to handle this job?
i need not to mix up any information between users...
i used c# windows app.
thanks in advance.
I assume you use static variables on server-side, right?
So, your issue happens because you use static variables.
Static variables are consistent in your class during all period of application is running. And that fields are shared between ALL processes which can use that class. Static variables was designed for this.
As a possible quick solution you can generate something like unique session Id. During client logs in to your system - you need just generate that id on client's side, send it with login information to server. In case of successful authentication server will store id in cache a key. And value of the cache can be object with user's name and other needs.
Every request to your server should be followed with that id. So your server will always know which user it is.
If you need more detailed answer please provide more information about app network structure and it's modules.
I've created a very simple Windows Form application that uses .NET 2.0 and runs from a single executable.
These single executables will be deployed to multiple users to prompt and collect information.
The catch is that I want to have the information emailed to a specific email address that can vary based on the user the executable is sent to. But, I do not want to rebuild the executable when the email changes.
I can pass command arguments to the executable via command line of course or a shortcut, but I simply want the user to enter information into the form and click submit and have it sent to a predefined email address that can vary based on the user the executable is sent to.
I can bundle the executable with a batch file that runs the executable with the command argument or a config file. But, I want to keep the deployment simple, one file if possible.
Is it possible to do this with an MSI? Am I totally missing something obvious here?
I want the person who is sending the executable out to the user to be able to easily change the email address that the WinForm will send the data to.
if your users are going to be changing the email address you might want to think about a simpler delivery mechanism than a config file, which is fragile in the sense that if a user deletes a > accidentally your app will throw System.Configuration.ConfigurationErrorsException.
One simpler solution than the app config file would be a text file with just the target email address in it, included in the same directory as the app. Your users would have an easier time editing it - or just dropping a new file in. Of course this relies on them having rights to that directory.
Another option is to treat it like a normal setting. Prompt the end user for the actual email on first run, and store it using a user specific setting, i.e. Properties.Settings.Default.SettingName. Then, give your users a UI function to change it on demand.
You could use an app.config file.
Right click the project and select Add->New Item->Application Configuration File
Have something like:
<configuration>
<appSettings>
<add key="UserEmail" value="test#test.com" />
</appSettings>
</coniguration>
And in your code retrieve the config value like:
string email = ConfigurationManager.AppSettings["UserEmail"];
Then you just need to change the value in the config file before sending it to the user, and they can also update it on their own.
One slightly different solution would be to have every instance send email to the same email address, with the 'from' being an address based on the user's Windows logged in account and domain.
Then, create a receiving email account that those emails arrive at with a filter to redirect the mail to the appropriate destination. You didn't say what email system you were using, but Exchange allows this quite simply, for example (as do other systems like GMail).
A more labor-intensive variant on this centralized design would be to create a small web service that your exe queries, with the web service telling the exe where it should send mail to. Again, you'd need a mapping table between Windows user and 'To' addresses.
I'm not sure if I understood your question, but here's my try:
You should check out the properties in visual studio:
Project -> yourProjectName Properties... -> Settings
There you can create variables, which can be either application or user scoped. By using user scoped variable, lets say userEmail, the program lets you save this information according to the logged in user. This way you can save like 20 different emails in this very same executable, depending on the logged in user.
Save the emails according to user:
Properties.Settings.Default.userEmail = "myemail#host.com";
Properties.Settings.Default.Save();
And read them the same way:
string email = Properties.Settings.Default.userEmail;
I am using mootools library to call webservices in an asp.net application. one of the web services is used to create new users in the database. I create an html dialog with mootools where the user can input his details, username, password, etc etc. upon submitting, the web service is called. We have a fingerprint scanner with a .net SDK. Is it possible for me to prompt the user for the finger print inside the webservice just before saving the details the user inputted in the html dialog?
Please note that the finger print scanner and the asp app will be available on one computer so to create new accounts users will go near the admins using this pc.
I am thinking of something like the below:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string NewMember(parameters)
{
JavaScriptSerializer js = new JavaScriptSerializer();
try
{
Database db = new Database();
//Prompt and get finger print from user
//create user
db.CreateNewMember(parameters with finger print code)
Thanks
No. You cannot use a web service to invoke your fingerprint reader directly. You'll need something client side (javascript/mootools/activex) to handle that.
One option (not too good) is if you can create a WPF/WinForms application using that fingerprint SDK and invoke that application from your WebService as you described above. For example:
insert user details into the database
execute your finger print reader app with user id as an argument
wait until finishes the job (scan/save fingerprint data to a temporary place with user id)
update your database record with the fingerprint details (read then delete from the temp place)
Or better if you just insert your user details into the database with empty fingerprint data using your WebService. Then later update your users record with fingerprint data using an independent WPF/WinForms application with direct DB access as it is won't block your WebService.
I asked this question before having the finger print at hand. Now that I have the finger print scanner at hand and used it with C# I realized that I do not need to store any finger print id in the database. the finger print scanner stores everything in it memory it just returns and id for the user.
I am going to create a windows app with c# for finger print events, from those events I get the id of the user which will match that in the database and from the app I will open or close the gate so practically no need to have it in the web app which is used to manage users only. When a new user is created on the web app I will show the id to the admin so he can add a finger print with same id to the user.