English 中文(简体)
添加Windows用户名称以数据库
原标题:Adding Windows User Name to database

ASP. NET MVC3 新b。

我正在研究使用窗口认证的MVC3内部网应用程序。 Windows auth是安装的,准备不成问题。

我需要的是,在用户首次查阅该笔数字时,抓住用户名称(Domainfirst.last),然后将该信息储存到数据库中,并将该名称与另一个独特的识别符号(数字和自动计算)。

我已经找到了获得用户名称的途径:

string user = WindowsIdentity.GetCurrent().Name;

我所要处理的问题是,这一变量在我的数据库中储存。

任何建议、背后建议、建议或判断都有利于资源。

如果这种情况在其他地方出现,如果我无法找到,则道歉。

Cheers Guys!

最佳回答

I think what you are looking for here is really how to store some info in a database What database system?

Check out http://www.datasprings.com/resources/articles-information/a-quick-guide-to-using-entity-framework

You can easily use the entity framework to store that value in the database which is what I think your question was really about. I do agree with Bryanmac though, you should be storing the SID not the login name in case the name changes. If you know it will NEVER change then you could store the name, but since they can technically change in Windows, I d be aware of this. If you have a specific question then on how to store that field using the Entity Framework, please post that.

问题回答

仔细——用户名称和显示名称可以改变。 我将避免将其储存在数据库中。

Instead, look at storing the SID (id of the user). The User property of the WindowsIdentity returns the SID. You can store and update the user name for display purposes but don t rely on it for typing the authenticating user back to the previous user in your DB.

另见这一SO员额:

我怎样才能获得目前的Windows账户的SID?

Persist the SID (along withusername for show only) and look up through SID.

当你提出MVC3申请时,有一种选择,即“内联网应用程序”,该软件已经安装了所有Windows Authentication梯子,你可能要检查一下,你在目前项目(或根据您的远处迁移)的法典中删除了。

它有一些特别法放到网上,以及它所编外文件。

阅读更多:

http://weblogs.asp.net/gunnarpeipman/archive/204/14/asp-net-mvc-3-intranet-application-template.aspx

页: 1

http://msdn.microsoft.com/en-us/library/gg7033 2228VS.98%29.aspx

Also you ll want to use User.Identity.Name to reference the person viewing the website.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签