Forms Authentication - Really really basic question

G

Guest

Hello!
I am just learning about forms authentication so please excuse this basic
question. I am using .NET 1.1 and C#.

I have created my web.config file and my login.aspx and the associated cs
file using
examples on MSDN. I have created a FormsAuthenticationTicket and cookie and
added the cookie to the response and then set the SetAuthCookie etc. When I
go to the redirected page, I am not sure how to read the cookie value so I
know who the user is!

In my FirstPage.aspx.cs's Page Load method, I have

string userID = Request.Cookies[FormsAuthentication.FormsCookieName].Value;

which is blank. My question is, once I read have created the ticket and
cookie, how to I read it ? Most examples I am looking at talk about the
creating tickets and cookies in forms authentication and not how to read the
cookie so any help will be greatly appreciated. Do I need to decrypt the
ticket?cookie?

Thanks,
 
G

Guest

Hi,
In below link it shows how to authenticate cookies in other pages.
http://www.15seconds.com/Issue/020220.htm
Search for User.Identity.IsAuthenticated in above link.
Also To enable forms authentication, cookies must be enabled on the client
browser. If the client disables cookies, the cookie generated by Forms
Authentication is lost and the client will not be able to authenticate.

Hope this helps
 
G

Guest

If the auth cookie is coming back from the browser, you should be getting the
cookie with your code:
Request.Cookies[FormsAuthentication.FormsCookieName].Value. Not sure if the
auth cookie is really sent to the browser (thru Response.Redirect (target
page after authentication) in your case.

Anyway, Context.User.Identity.Name gives the currently logged on user's name
(including Forms Auth mode). However, this works only if the auth cookie was
received from the browser.
 
G

Guest

Thank you Siva and Manish. I am now getting the user name like so:
Page.User.Identity.Name.

Also, I printed the value for Page.User.Identity.IsAuthenticated (True)
and Page.User.Identity.AuthenticaionType (Forms), so I am guessing that I
am using forms authentication and the cookie is being sent to the browser.

What you are saying is that
Request.Cookies[FormsAuthentication.FormsCookieName].Value should also have
the value of the user name, right ? I will recheck my code to see why that
is blank.

Thanks,
LW

Siva M said:
If the auth cookie is coming back from the browser, you should be getting the
cookie with your code:
Request.Cookies[FormsAuthentication.FormsCookieName].Value. Not sure if the
auth cookie is really sent to the browser (thru Response.Redirect (target
page after authentication) in your case.

Anyway, Context.User.Identity.Name gives the currently logged on user's name
(including Forms Auth mode). However, this works only if the auth cookie was
received from the browser.

LW said:
Hello!
I am just learning about forms authentication so please excuse this basic
question. I am using .NET 1.1 and C#.

I have created my web.config file and my login.aspx and the associated cs
file using
examples on MSDN. I have created a FormsAuthenticationTicket and cookie and
added the cookie to the response and then set the SetAuthCookie etc. When I
go to the redirected page, I am not sure how to read the cookie value so I
know who the user is!

In my FirstPage.aspx.cs's Page Load method, I have

string userID = Request.Cookies[FormsAuthentication.FormsCookieName].Value;

which is blank. My question is, once I read have created the ticket and
cookie, how to I read it ? Most examples I am looking at talk about the
creating tickets and cookies in forms authentication and not how to read the
cookie so any help will be greatly appreciated. Do I need to decrypt the
ticket?cookie?

Thanks,
 
G

Guest

Hi,
just a gentle reminder.If you have found our post useful then please do
press Yes below
 
G

Guest

LW,

The cookie will NOT have the actual user name, but the encrypted
FormsAuthenticationTicket instance represnting the current user name and
additional data. To get the user name from the cookie value:

FormsAuthentication.Decrypt
(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name

LW said:
Thank you Siva and Manish. I am now getting the user name like so:
Page.User.Identity.Name.

Also, I printed the value for Page.User.Identity.IsAuthenticated (True)
and Page.User.Identity.AuthenticaionType (Forms), so I am guessing that I
am using forms authentication and the cookie is being sent to the browser.

What you are saying is that
Request.Cookies[FormsAuthentication.FormsCookieName].Value should also have
the value of the user name, right ? I will recheck my code to see why that
is blank.

Thanks,
LW

Siva M said:
If the auth cookie is coming back from the browser, you should be getting the
cookie with your code:
Request.Cookies[FormsAuthentication.FormsCookieName].Value. Not sure if the
auth cookie is really sent to the browser (thru Response.Redirect (target
page after authentication) in your case.

Anyway, Context.User.Identity.Name gives the currently logged on user's name
(including Forms Auth mode). However, this works only if the auth cookie was
received from the browser.

LW said:
Hello!
I am just learning about forms authentication so please excuse this basic
question. I am using .NET 1.1 and C#.

I have created my web.config file and my login.aspx and the associated cs
file using
examples on MSDN. I have created a FormsAuthenticationTicket and cookie and
added the cookie to the response and then set the SetAuthCookie etc. When I
go to the redirected page, I am not sure how to read the cookie value so I
know who the user is!

In my FirstPage.aspx.cs's Page Load method, I have

string userID = Request.Cookies[FormsAuthentication.FormsCookieName].Value;

which is blank. My question is, once I read have created the ticket and
cookie, how to I read it ? Most examples I am looking at talk about the
creating tickets and cookies in forms authentication and not how to read the
cookie so any help will be greatly appreciated. Do I need to decrypt the
ticket?cookie?

Thanks,
 
J

Juan T. Llibre

Please don't spam this newsgroup with your requests for votes.

Many people can't even see the Yes button, because they're using
newsreaders, not browsers, to ask questions and reply to them.





Manish Bafna said:
Hi,
just a gentle reminder.If you have found our post useful then please do
press Yes below
--
If my answer helped you,then please do press Yes below.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.



LW said:
Hello!
I am just learning about forms authentication so please excuse this basic
question. I am using .NET 1.1 and C#.

I have created my web.config file and my login.aspx and the associated cs
file using
examples on MSDN. I have created a FormsAuthenticationTicket and cookie and
added the cookie to the response and then set the SetAuthCookie etc. When I
go to the redirected page, I am not sure how to read the cookie value so I
know who the user is!

In my FirstPage.aspx.cs's Page Load method, I have

string userID = Request.Cookies[FormsAuthentication.FormsCookieName].Value;

which is blank. My question is, once I read have created the ticket and
cookie, how to I read it ? Most examples I am looking at talk about the
creating tickets and cookies in forms authentication and not how to read the
cookie so any help will be greatly appreciated. Do I need to decrypt the
ticket?cookie?

Thanks,
 
G

Guest

I just voted for you!
:)
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net




Juan T. Llibre said:
Please don't spam this newsgroup with your requests for votes.

Many people can't even see the Yes button, because they're using
newsreaders, not browsers, to ask questions and reply to them.





Manish Bafna said:
Hi,
just a gentle reminder.If you have found our post useful then please do
press Yes below
--
If my answer helped you,then please do press Yes below.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.



LW said:
Hello!
I am just learning about forms authentication so please excuse this basic
question. I am using .NET 1.1 and C#.

I have created my web.config file and my login.aspx and the associated cs
file using
examples on MSDN. I have created a FormsAuthenticationTicket and cookie and
added the cookie to the response and then set the SetAuthCookie etc. When I
go to the redirected page, I am not sure how to read the cookie value so I
know who the user is!

In my FirstPage.aspx.cs's Page Load method, I have

string userID = Request.Cookies[FormsAuthentication.FormsCookieName].Value;

which is blank. My question is, once I read have created the ticket and
cookie, how to I read it ? Most examples I am looking at talk about the
creating tickets and cookies in forms authentication and not how to read the
cookie so any help will be greatly appreciated. Do I need to decrypt the
ticket?cookie?

Thanks,
 
G

Guest

Siva/Manish,

This is exactly what I was looking for:

FormsAuthentication.Decrypt
(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name

Thank you very much for your helpful posts!
LW

Siva M said:
LW,

The cookie will NOT have the actual user name, but the encrypted
FormsAuthenticationTicket instance represnting the current user name and
additional data. To get the user name from the cookie value:

FormsAuthentication.Decrypt
(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name

LW said:
Thank you Siva and Manish. I am now getting the user name like so:
Page.User.Identity.Name.

Also, I printed the value for Page.User.Identity.IsAuthenticated (True)
and Page.User.Identity.AuthenticaionType (Forms), so I am guessing that I
am using forms authentication and the cookie is being sent to the browser.

What you are saying is that
Request.Cookies[FormsAuthentication.FormsCookieName].Value should also have
the value of the user name, right ? I will recheck my code to see why that
is blank.

Thanks,
LW

Siva M said:
If the auth cookie is coming back from the browser, you should be getting the
cookie with your code:
Request.Cookies[FormsAuthentication.FormsCookieName].Value. Not sure if the
auth cookie is really sent to the browser (thru Response.Redirect (target
page after authentication) in your case.

Anyway, Context.User.Identity.Name gives the currently logged on user's name
(including Forms Auth mode). However, this works only if the auth cookie was
received from the browser.

:

Hello!
I am just learning about forms authentication so please excuse this basic
question. I am using .NET 1.1 and C#.

I have created my web.config file and my login.aspx and the associated cs
file using
examples on MSDN. I have created a FormsAuthenticationTicket and cookie and
added the cookie to the response and then set the SetAuthCookie etc. When I
go to the redirected page, I am not sure how to read the cookie value so I
know who the user is!

In my FirstPage.aspx.cs's Page Load method, I have

string userID = Request.Cookies[FormsAuthentication.FormsCookieName].Value;

which is blank. My question is, once I read have created the ticket and
cookie, how to I read it ? Most examples I am looking at talk about the
creating tickets and cookies in forms authentication and not how to read the
cookie so any help will be greatly appreciated. Do I need to decrypt the
ticket?cookie?

Thanks,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top