3dmax渲染教程,幼交,psp玩游戏卡
一般互联网应用,如人人网,微博,都是需要用户登录的,如果用户不登陆,就不能使用此网站。所以,这里都是用formauthentication,要求用户填写用户名与密码,然后登录成功后,formauthentication.setauthcookie()方式向客户端cookie中写入一个认证token.
一般企业内部的应用,企业内部信息,使用windows auhentication. 因为企业内部都有自己的域,员工的电脑都有这个域内部的一个id,而且这个id是唯一的,所有的操作都会通过这个id进行。企业内部的信息系统是不需要用户注册的,用的都是这个id,所以,使用windows authentication. 但是需要注意的是,formauthentication.setauthcookie()往往写入的都是很简单的字段,一般是username, 而真正系统中的user实体是一个很复杂的对象,有很多信息,所以,每次当用户进入这个系统后,程序会根据用户的id或者username,找到中对应的详细的user对象,然后放到session中。一般这些操作是在global.asax.cs中的session_start()中进行的。
protected void session_start(object sender, eventargs e) { var securityhelper = new securityhelper(); securityhelper.authenticate(); } public class securityhelper { private string getwindowsvcnusername() { // get windows user var loggeduser = system.web.httpcontext.current.user.identity; if (loggeduser != null) { string username = loggeduser.name; username = username.substring(username.indexof('\\') + 1); username = username.toupper(); return username; } return null; } public virtual bool authenticate() { // inject implementation of the userservice through di if (userservice == null) { userservice = container.resolve<userservice>(); } string userloggin = getwindowsvcnusername(); // get user from external authorization system var user = userservice.getuser(userloggin); if (user == null) { //说明数据库中没有这个用户,此时可以根据需要设定相应的逻辑,可以提示该用户不能访问此系统,也可以为此用户建立一个guset账号,根据需要而定 } // set session system.web.httpcontext.session.add("user", user); return true; } } protected void session_start(object sender, eventargs e) { var securityhelper = new securityhelper(); securityhelper.authenticate(); } public class securityhelper { private string getwindowsvcnusername() { // get windows user var loggeduser = system.web.httpcontext.current.user.identity; if (loggeduser != null) { string username = loggeduser.name; username = username.substring(username.indexof('\\') + 1); username = username.toupper(); return username; } return null; } public virtual bool authenticate() { // inject implementation of the userservice through di if (userservice == null) { userservice = container.resolve<userservice>(); } string userloggin = getwindowsvcnusername(); // get user from external authorization system var user = userservice.getuser(userloggin); if (user == null) { //说明数据库中没有这个用户,此时可以根据需要设定相应的逻辑,可以提示该用户不能访问此系统,也可以为此用户建立一个guset账号,根据需要而定 } // set session system.web.httpcontext.session.add("user", user); return true; } }
此后,在该session生存周期内,需要user信息的时候,只要从session中拿就可以了,因为session中有一个详细的user对象
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Blazor server side 自家的一些开源的, 实用型项目的进度之 CEF客户端
.NET IoC模式依赖反转(DIP)、控制反转(Ioc)、依赖注入(DI)
vue+.netcore可支持业务代码扩展的开发框架 VOL.Vue 2.0版本发布
网友评论