用户名 [英] User Name

查看:84
本文介绍了用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个webapp,用户需要在登录表单上输入登录ID和

密码。我在我的web.config中编写了表单身份验证。

一旦用户登录,我想在其他形式的

应用程序中使用登录ID。我最终会将记录保存到SQL数据库中,我希望登录

id自动输入到登录

页面以外的表单上的字段中。帮助。

解决方案

会话变量。


Eliyahu


汤姆诺瓦克 <为了****** @ discussions.microsoft.com>在消息中写道

新闻:AF ********************************** @ microsof t.com ...

我正在编写一个webapp,用户需要在登录表单上输入登录ID和
密码。我在
web.config中编写了表单身份验证码。一旦用户登录,我想在app b的其他形式的
中使用登录ID。我最终会将记录保存到SQL数据库中,并且我希望将
登录ID自动输入到登录
页面以外的表单上的字段中。帮助。



如何定义和使用它们?


" Eliyahu Goldin"写道:

会话变量。

Eliyahu

汤姆诺瓦克 <为了****** @ discussions.microsoft.com>在消息中写道
新闻:AF ********************************** @ microsof t.com。 ..

我正在编写一个webapp,用户需要在登录表单上输入登录ID和
密码。我在我的


web.config中编写了表单身份验证。

一旦用户登录,我想以其他形式使用登录ID


app。我最终会将记录保存到SQL数据库,我希望


登录

id自动输入到登录以外的表单上的字段
页面。帮助。




Tom Nowak< To ****** @ discussion.microsoft.com>键入:

如何定义和使用它们?




认证过程后,在会话变量中插入值


Session [" UserId"] = UserId;


使用变量


if(Session [" ; UserId"]!= null)

int UserId = Int32.Parse(Session [" UserId"]);


如果您需要更多信息对于经过身份验证的用户,您可以考虑使用
创建自己的用户对象,在身份验证过程后填充它b / b $ b并将其保存在会话变量中。例如:


//用户已通过身份验证


UserInfo user = new UserInfo();

用户。 Id = UserId;

user.Name =姓名;

user.Email =电子邮件;


会话[" CurrentUser" ] = user;


当你需要检索这些信息时......


if(Session [" CurrentUser" ;]!= null)

UserInfo user =(UserInfo)Session [" CurrentUser"];


int Id = user.Id;

string Name = user.Name;

string Email = user.Email;


.....等等。


如果您只需要恢复当前经过身份验证的用户的名称,那么

就可以使用Current.User.Identity.Name。


-

Davide Vernole

MVP ASP / ASP.NET

微软认证解决方案开发人员


I am writing a webapp in which a user is required to enter a login id and
password on a login form. I have forms authenticaion coded in my web.config.
Once the user is logged in, I want to use the login id in other forms of the
app. I will eventually save a record to a SQL database, and I want the login
id to be automatically entered in a field on a form other than the login
page. Help.

解决方案

Session variables.

Eliyahu

"Tom Nowak" <To******@discussions.microsoft.com> wrote in message
news:AF**********************************@microsof t.com...

I am writing a webapp in which a user is required to enter a login id and
password on a login form. I have forms authenticaion coded in my web.config. Once the user is logged in, I want to use the login id in other forms of the app. I will eventually save a record to a SQL database, and I want the login id to be automatically entered in a field on a form other than the login
page. Help.



How do I define and use them?

"Eliyahu Goldin" wrote:

Session variables.

Eliyahu

"Tom Nowak" <To******@discussions.microsoft.com> wrote in message
news:AF**********************************@microsof t.com...

I am writing a webapp in which a user is required to enter a login id and
password on a login form. I have forms authenticaion coded in my


web.config.

Once the user is logged in, I want to use the login id in other forms of


the

app. I will eventually save a record to a SQL database, and I want the


login

id to be automatically entered in a field on a form other than the login
page. Help.




Tom Nowak <To******@discussions.microsoft.com> typed:

How do I define and use them?



After the authentication process insert the value in a session variable

Session["UserId"] = UserId;

To use the variable

if(Session["UserId"] != null)
int UserId = Int32.Parse(Session["UserId"]);

If you need more info about your authenticated user, you could consider to
create your own user object, populate it after the authentication process
and than save it in a session variable. For example:

//user is authenticated

UserInfo user = new UserInfo();
user.Id = UserId;
user.Name = Name;
user.Email = Email;

Session["CurrentUser"] = user;

Than, when you need to retrieve this information ......

if(Session["CurrentUser"] != null)
UserInfo user = (UserInfo)Session["CurrentUser"];

int Id = user.Id;
string Name = user.Name;
string Email = user.Email;

.....and so on.

If you need to recover only the name of the current authenticated user, you
could use the Current.User.Identity.Name.

--
Davide Vernole
MVP ASP/ASP.NET
Microsoft Certified Solution Developer


这篇关于用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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