如何在asp .net C#登录和注册会员资料页面中创建会话
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15199415/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to Create Session in asp .net C# login and registration memberprofile page
提问by user2110292
I am new to ASP .net C# i created registration,login and member profile page
我是 ASP .net C# 的新手,我创建了注册、登录和会员资料页面
after all validations data is stored in database.. and login page also working fine...
在所有验证数据都存储在数据库中之后......登录页面也工作正常......
i dont know about sessions ..how can i create session and how to make login module more effective using sessions?
我不知道会话..如何创建会话以及如何使用会话使登录模块更有效?
thanks in advance
提前致谢
采纳答案by Ravi Gadag
- Session is Per User basis.
- You can store the session in SqlServer for to reduce the load on the server
- 会话是基于每个用户的。
- 您可以将会话存储在 SqlServer 中以减少服务器上的负载
you can create Session like this
你可以像这样创建会话
Session["yourKey"]=someValue;
to read this value
读取这个值
if(Session["yourKey"]!=null)
{
//use the Session values.
}
you can use Forms Authentication for Better Approach for login . Forms Authentication
您可以使用 Forms Authentication for Better Approach 进行登录。表单认证
回答by Stefano Altieri
A session is something the asp.net engine creates for you each time a user logins. This is a good article to start: Asp.net Session
会话是 ASP.NET 引擎在用户每次登录时为您创建的内容。这是一篇很好的文章开始:Asp.net Session
回答by Usama Raees
Using the Session
is an easy way to transfer values.
使用Session
是一种传递值的简单方法。
You can do something like this:
你可以这样做:
Create a session variable:
创建会话变量:
Session["name"] = "Any Name";
Now, let's make a condition with this variable in another class:
现在,让我们在另一个类中用这个变量创建一个条件:
if(Session["name"] == "Any Name")
{
//To do Your Code Here
}