如何在提交按钮单击时在数据库中保存计算机全名 [英] how to save computer full name in database on submit button click

查看:56
本文介绍了如何在提交按钮单击时在数据库中保存计算机全名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,



我想在数据库中插入记录时将数据库全名保存在数据库表中。



我有一个网页,其中包含文本框和提交按钮,用于将数据保存在数据库表中。



在表中插入记录时,我想保存计算机登录用户名也是。



这是我的代码,我正在使用。但它存储了计算机名称。我需要完整的电脑名称这样的kumarPC / Rkumar





声明

------- -

string machineName = System.Environment.MachineName;





在插入查询中

-----------

'+ machineName.ToString()+'



机器名称是存储,但需要保存用户计算机登录名称也作为kumarPC / Rkumar







请帮助

谢谢。

hi friends,

I want to Save Computer Full Name in database table while am inserting records in database.

I have a webpage which consists of textboxes and submit button to save data in database table.

while inserting record in table, i want to save computer login username also.

This is my code, am using. But it stores Computer Name. I need full computer Name like this kumarPC/Rkumar


Declaring
--------
string machineName = System.Environment.MachineName;


In Insert Query
-----------
'" + machineName.ToString() + "'

Machine name is storing but need to save Users Computer login name also as kumarPC/Rkumar



Please help
THANKS.

推荐答案

string machineName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;





更喜欢WindowsIdentity.GetCurrent()的原因是这将返回运行应用程序的帐户。这不一定是当前登录到Windows的帐户(想想RunAs或模拟/委派)。因此,如果您想了解登录用户,请使用环境(如果您信任它)。如果您想使用WindowsIdentity.GetCurrent()知道应用程序运行的安全上下文。有关详细信息,请参见 msdn.microsoft.com/en-us/library/...


你看过System.Environment.UserName吗?
have you had a look at System.Environment.UserName ?


这篇关于如何在提交按钮单击时在数据库中保存计算机全名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆