ASP.NET Forms Authentication With Only UserName

痴心易碎 提交于 2019-12-05 10:35:54

问题


I have a bit of a hybrid situation on my hands. I'm writing an intranet asp.net web app. I don't want to use full blown Windows Authentication, because I don't have proper groups set up in Active Directory to be able to authenticate users simply based on what group they are in. Up until now, I had created a membership database, and was manually authenticating users based on their NT Login. The app is getting more complex, and I'm looking at using the Membership and Roles providers to authenticate users. Here's my issue: I want to be able to authenticate users just based on their NT, but I don't want to use Windows Authentication. I want to write my own provider to plug into the membership and roles providers, and use Forms authentication, but make it transparent. Based on a Users table, I want to be able to authenticate the user or redirect them based on their NT alone. Is this possible, or am I stuck writing my own small framework to accomplish this? I would like to take advantage of the provider framework if at all possible.


回答1:


Set your web.config to use Forms Authentication.
Make sure Integrated Authentication is turned on in IIS (you may need to disable anonymous as well). This will allow you to get the user's NT name.

You can get the user's NT name with:

  Request.ServerVariables["LOGON_USER"]  

You can log the user in, no password needed, with:

  FormsAuthentication.RedirectFromLoginPage( userName, false ); 


来源:https://stackoverflow.com/questions/197357/asp-net-forms-authentication-with-only-username

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!