简体   繁体   English

如何让asp.net登录控件自动验证以前认证的用户?

[英]How to get the asp.net login control to auto authenticate a previously authenticated user?

I am trying to to set up the login control to remember the login credentials of a user who has previously entered their user name and password successfully. 我正在尝试设置登录控件以记住之前已成功输入用户名和密码的用户的登录凭据。 I set the remember me property to true, but it doesnt seem to triger any events where I could read the cookie and auto login the user. 我将remember me属性设置为true,但它似乎没有任何可以读取cookie并自动登录用户的事件。

Is there a straightforward mechanism to accomplish this? 是否有直接的机制来实现这一目标?

You need to Google for Forms Authentication in ASP.NET 2.0 您需要在ASP.NET 2.0中使用 Google进行表单身份验证

You will need to set up your application (via web.config) and may also need to alter IIS settings. 您需要设置应用程序(通过web.config),还可能需要更改IIS设置。 While it's all quite straightforward, there are heaps of settings that can be used, so best is to read some of the articles. 虽然它很简单,但可以使用大量设置,所以最好阅读一些文章。 ScottGu has a blog entry that goes into a lot of good detail. ScottGu有一篇博客文章 ,详细介绍了很多细节。

There are also many good video's at www.asp.net including these Security Tutorials www.asp.net上还有很多很好的视频,包括这些安全教程

try How to: Create an ASP.NET Login Page and Walkthrough: Creating a Web Site with Membership and User Login . 尝试如何:创建ASP.NET登录页面演练:创建具有成员身份和用户登录的网站 If I recall, you still have to do the authentication yourself unless you use the Sql Server Membership provider. 如果我记得,除非您使用Sql Server Membership提供程序,否则您仍需要自己进行身份验证。 In that case you still have to set up the database and web.config. 在这种情况下,您仍然需要设置数据库和web.config。


Essentially, once you've set up configuration properly, you have a login page. 基本上,一旦你正确设置了配置,你就有了一个登录页面。 In that login page you tell Forms Authentication to create the authentication ticket for you once you authenticate them: 在登录页面告诉窗体身份验证创建身份验证票给你一旦验证他们的身份:

if (VerifyUser(name, password) ) // this is not a framework method
    FormsAuthentication.RedirectFromLoginPage(
        userName, false); // no persistent cookie

If you want to read the authentication ticket data (from anywhere else). 如果要读取身份验证票证数据(来自其他任何位置)。

// output just writes to a StringBuilder 'sb' 
output(sb, "Identity.AuthenticationType", Page.User.Identity.AuthenticationType);

FormsIdentity fi = Page.User.Identity as FormsIdentity;
if (fi == null)
{
    output(sb, "Identity Type", Page.User.Identity.ToString());
    return;
}

output(sb, "FormsIdentity.Ticket.IssueDate", fi.Ticket.IssueDate);
output(sb, "FormsIdentity.Ticket.Expiration", fi.Ticket.Expiration);
output(sb, "FormsIdentity.Ticket.Name", fi.Ticket.Name);
output(sb, "FormsIdentity.Ticket.CookiePath", fi.Ticket.CookiePath);
output(sb, "FormsIdentity.Ticket.UserData", fi.Ticket.UserData);
output(sb, "FormsIdentity.Ticket.Version", fi.Ticket.Version);
output(sb, "FormsIdentity.Ticket.IsPersistent", fi.Ticket.IsPersistent);

The point is, once authenticated, asp.net will only redirect the user to the login page if the authentication ticket has expired and the user is on a protected page. 关键是,一旦通过身份验证,如果身份验证票证已过期且用户位于受保护的页面上,asp.net将仅将用户重定向到登录页面。 Asp.net doesn't keep asking you to authenticate the user unnecessarily. Asp.net不会一直要求您不必要地对用户进行身份验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从ASP.NET网页获取SharePoint身份验证的用户? - How to get the SharePoint authenticated user from an ASP.NET webpage? 如何在asp.net中获取Windows身份验证用户的用户名? - How to get the username of windows authenticated user in asp.net? 如果我们经过Micorosoft Federation的身份验证,如何在ASP.NET中自定义登录帐户以进行登录控制? - How to customize login account for Login control in ASP.NET if we are authenticated by Micorosoft Federation? 首次登录后ASP.Net登录控件无法通过身份验证 - ASP.Net Login control fails to authenticate after first login ASP.NET 登录控制 - 使用 Authenticate 事件保护 SQLi? - ASP.NET Login Control - protect from SQLi with Authenticate event? 成功登录并重定向到主页后,asp.net 用户未通过身份验证 - asp.net User not authenticated after successful login and redirect to homepage asp.net中的登录控件如何保留当前用户的信息? - login control in asp.net how to keep information of current user? 如何在ASP.NET中验证用户 - How to Authenticate user in ASP.NET 在ASP Classic中从ASP.NET获取经过身份验证的用户 - Get authenticated user from ASP.NET in ASP classic 在 ASP.NET MVC 中获取经过身份验证的用户数据 - Get Authenticated Identity User data in ASP.NET MVC
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM