开发者

Combine form based authentication in ASP.NET with direct authentication trough URL GET parameters

开发者 https://www.devze.com 2023-04-11 09:08 出处:网络
I\'m new in ASP.NET and already got a lot of answers here searching on google (THX!). My task is now to build a website开发者_JS百科, where authentication is required, so I choosed form based authetic

I'm new in ASP.NET and already got a lot of answers here searching on google (THX!). My task is now to build a website开发者_JS百科, where authentication is required, so I choosed form based authetication, which is working well. I need to add functionality, when user can click on link and after redirecting to that website he will get automatically authorized based on GET parameters.

For example: http://www.mysite.com/login.aspx?username=xxx&password=yyy

So after clicking on such link he will skip login page and continue to page behind.

Could you please help me with that question?

P.S. I'm aware, that it is not secure and username with password will be visible as clear text, but here we are talking about generated username and password which will be available just for one day and it is required to identify user to do one request.


You could do something like.

Make sure the username and password are in the querystring, and then assign them to a username and password varaible.

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

For this to work you will need to import/using System.Web.Security. The true value tells your authentication to set a persistent cookie value.


If you are using SQL Server as the database, the easiest way is to use ASP.NET membership provider. By using that you will be able to authenticate user in an effective way. Here you can use Aspnet_regsql.exe to create required batabase tables. There is a good explanation about Creating a Web Site with Membership and User Login

Hope this will help

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号