如何使用session在asp网站上登录用户 [英] how to login user in asp website using session

查看:131
本文介绍了如何使用session在asp网站上登录用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是.net的新手所以请告诉我如何使用asp.net中的会话登录用户。

请告诉我完整的程序。

谢谢。

i am new to the .net so please tell me how to login user by using session in asp.net.
please tell me complete procedure.
Thank you.

推荐答案

我建​​议您使用FormsAuthentication而不是Session。但是,要使用Session,您需要一个将验证用户的页面,然后您可以将其用户名存储在Session变量中。然后在每个页面上,您需要检查以确保填充了Session变量,如果不是,则必须将它们重定向到登录页面。您可以使用您的所有页面继承的BasePage类来执行此操作;然而,让ASP.Net使用FormsAuthentication管理它要容易得多
I would recommend you use FormsAuthentication instead of Session. However, to use Session you need a page that will validate the user and then you can store their username in a Session variable. Then on every single page you''ll need to check to make sure that Session variable is filled in and if it is not you''ll have to redirect them to the login page. You can do this using a BasePage class that all of your pages inherit from; however, it is a lot easier to let ASP.Net manage it for you using FormsAuthentication


检查下面msdn链接的formsAuthentication示例

解释:ASP.NET 2.0中的表单身份验证 [ ^ ]

另请查看以下链接

使用C#在ASP.NET中进行表单身份验证:高级 [ ^ ]

查看视频

使用ASP.NET Forms身份验证 [ ^ ]
Check below msdn link for formsAuthentication example
Explained: Forms Authentication in ASP.NET 2.0[^]
Also Check below link
Forms Authentication in ASP.NET with C#: Advance[^]
Check Video on
Using ASP.NET Forms Authentication [^]


例如你想访问admin.aspx

首先检查session(user_id)

如果是则将其重定向到login.aspx
for example you wanna access to admin.aspx
first check session("user_id")
if it is "" then redirect it to login.aspx


这篇关于如何使用session在asp网站上登录用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆