我是ASP.NET的新手,已经在谷歌搜索了很多答案(THX!)。 我的任务是建立一个需要身份验证的网站,所以我选择了基于表单的身份验证,这种方式运行良好。 我需要添加功能,当用户点击链接时,重定向到该网站后,他将根据GET参数自动获得授权。
例如: http://www.mysite.com/login.aspx?username=xxx&password=yyy
因此,点击此链接后,他将跳过登录页面并继续向后翻页。
你能帮我解决这个问题吗?
P.S。我知道,它不安全,带有密码的用户名将以明文形式显示,但这里我们讨论的是生成的用户名和密码,这些用户名和密码只能在一天内使用,并且需要识别用户做一个请求
答案 0 :(得分:0)
你可以做类似的事情。
确保用户名和密码位于querystring
,然后将其分配给username
和password
可选。
C#
if (FormsAuthentication.Authenticate(username, password))
{
FormsAuthentication.SetAuthCookie(username, true);
FormsAuthentication.RedirectFromLoginPage(username, true);
}
else { // not authenticated. do something }
vb.net
If FormsAuthentication.Authenticate(username, password) Then
FormsAuthentication.SetAuthCookie(username, true)
FormsAuthentication.RedirectFromLoginPage(username, true)
Else
' not authenticated. do something.
End If
为此,您需要导入/使用System.Web.Security。 true
值告诉您的身份验证设置持久cookie值。
答案 1 :(得分:-1)
如果您使用SQL Server
作为database
,最简单的方法是使用ASP.NET membership
提供商。通过使用它,您将能够以有效的方式authenticate
用户。在这里,您可以使用Aspnet_regsql.exe创建所需的batabase表。关于Creating a Web Site with Membership and User Login
希望这会有所帮助