By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,148 Members | 779 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,148 IT Pros & Developers. It's quick & easy.

Forms Authentication - Really really basic question

P: n/a
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,
Apr 24 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
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
--
If my answer helped you,then please do press Yes below.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

"LW" wrote:
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,
Apr 24 '07 #2

P: n/a
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" wrote:
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,
Apr 24 '07 #3

P: n/a
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" wrote:
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" wrote:
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,
Apr 24 '07 #4

P: n/a
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" wrote:
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,
Apr 24 '07 #5

P: n/a
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" wrote:
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" wrote:
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" wrote:
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,
Apr 24 '07 #6

P: n/a
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.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Manish Bafna" <Ma*********@discussions.microsoft.comwrote in message
news:11**********************************@microsof t.com...
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" wrote:
>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,

Apr 24 '07 #7

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


"Juan T. Llibre" wrote:
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.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Manish Bafna" <Ma*********@discussions.microsoft.comwrote in message
news:11**********************************@microsof t.com...
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" wrote:
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,


Apr 24 '07 #8

P: n/a
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" wrote:
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" wrote:
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" wrote:
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" wrote:
>
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,
Apr 25 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.