473,748 Members | 10,569 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Forms Authentication - Really really basic question

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 FormsAuthentica tionTicket 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[FormsAuthentica tion.FormsCooki eName].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
8 2149
Hi,
In below link it shows how to authenticate cookies in other pages.
http://www.15seconds.com/Issue/020220.htm
Search for User.Identity.I sAuthenticated 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 FormsAuthentica tionTicket 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[FormsAuthentica tion.FormsCooki eName].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
If the auth cookie is coming back from the browser, you should be getting the
cookie with your code:
Request.Cookies[FormsAuthentica tion.FormsCooki eName].Value. Not sure if the
auth cookie is really sent to the browser (thru Response.Redire ct (target
page after authentication) in your case.

Anyway, Context.User.Id entity.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 FormsAuthentica tionTicket 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[FormsAuthentica tion.FormsCooki eName].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
Thank you Siva and Manish. I am now getting the user name like so:
Page.User.Ident ity.Name.

Also, I printed the value for Page.User.Ident ity.IsAuthentic ated (True)
and Page.User.Ident ity.Authenticai onType (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[FormsAuthentica tion.FormsCooki eName].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[FormsAuthentica tion.FormsCooki eName].Value. Not sure if the
auth cookie is really sent to the browser (thru Response.Redire ct (target
page after authentication) in your case.

Anyway, Context.User.Id entity.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 FormsAuthentica tionTicket 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[FormsAuthentica tion.FormsCooki eName].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
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 FormsAuthentica tionTicket 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[FormsAuthentica tion.FormsCooki eName].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
LW,

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

FormsAuthentica tion.Decrypt
(Request.Cookie s[FormsAuthentica tion.FormsCooki eName].Value).Name

"LW" wrote:
Thank you Siva and Manish. I am now getting the user name like so:
Page.User.Ident ity.Name.

Also, I printed the value for Page.User.Ident ity.IsAuthentic ated (True)
and Page.User.Ident ity.Authenticai onType (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[FormsAuthentica tion.FormsCooki eName].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[FormsAuthentica tion.FormsCooki eName].Value. Not sure if the
auth cookie is really sent to the browser (thru Response.Redire ct (target
page after authentication) in your case.

Anyway, Context.User.Id entity.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 FormsAuthentica tionTicket 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[FormsAuthentica tion.FormsCooki eName].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
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*********@di scussions.micro soft.comwrote in message
news:11******** *************** ***********@mic rosoft.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 FormsAuthentica tionTicket 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[FormsAuthentica tion.FormsCooki eName].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?cooki e?

Thanks,

Apr 24 '07 #7
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*********@di scussions.micro soft.comwrote in message
news:11******** *************** ***********@mic rosoft.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 FormsAuthentica tionTicket 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[FormsAuthentica tion.FormsCooki eName].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
Siva/Manish,

This is exactly what I was looking for:

FormsAuthentica tion.Decrypt
(Request.Cookie s[FormsAuthentica tion.FormsCooki eName].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
FormsAuthentica tionTicket instance represnting the current user name and
additional data. To get the user name from the cookie value:

FormsAuthentica tion.Decrypt
(Request.Cookie s[FormsAuthentica tion.FormsCooki eName].Value).Name

"LW" wrote:
Thank you Siva and Manish. I am now getting the user name like so:
Page.User.Ident ity.Name.

Also, I printed the value for Page.User.Ident ity.IsAuthentic ated (True)
and Page.User.Ident ity.Authenticai onType (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[FormsAuthentica tion.FormsCooki eName].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[FormsAuthentica tion.FormsCooki eName].Value. Not sure if the
auth cookie is really sent to the browser (thru Response.Redire ct (target
page after authentication) in your case.
>
Anyway, Context.User.Id entity.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 FormsAuthentica tionTicket 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[FormsAuthentica tion.FormsCooki eName].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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1710
by: chrisnet | last post by:
We use a .NET web application on one server that is using basic integrated authentication and therefore getting the windows prompt for domain credentials. These credentials are then passed to a sharepoint server so the user can access certain documents, etc. We want to change the web app to use ..NET forms authentication so we can get rid of the ugly windows prompt. My question is if using the forms based domain authentication will still...
3
2720
by: Nick | last post by:
I am working a new application...well actually a series of applications for my company. They want internal users to be able to go to a site and everything regarding security is transparent, however we will have brokers and customers that also need to connect and will require a username and password. In this case we were going to store their credentials in a SQL database. Internal users will have the ability to access the same resources...
2
2333
by: Summa | last post by:
Hi, In ASP.NET, i've written a class that handles URLRewrite. So that all requests to say "default.aspx?id=2&basic=1" is returned as "basic.1/2.aspx". It works beautifully...But but but....Using forms authentication the authentification redirect somehow get redirected using the non-rewritten url. That is....the redirect happens on the rewritten URL. Exampel: I call "mysite.com/basic.1/2.aspx". 1. The URLRewrite rewrites the URL to...
4
2746
by: Greg Burns | last post by:
I have built a web app that uses forms authentication. There isn't a "remember me" feature (i.e. the authentication cookie is not permanent). When you close the browser, and open a new one, you must log in again. This is the behavior I expected. I just discovered that if I have a browser window open (to anything) prior to opening my web app in a new browser window, it appears to share session information. I can then open and close my...
4
3347
by: Joey Powell | last post by:
Hello, I originally configured my application to use persistent cookies in error. Now, I need to find a way to disable those cookies. I have tried changing usernames and passwords for all of the users, but that doesn't help - they can still access our site using their old persistent cookies. How can I disable them and force the users to log in again?
2
259
by: Brian Shannon | last post by:
I have an intranet site I created when I first began .NET and it is very basic. Now that I have developed my skills I am looking to revamp the old with something new. I really like the idea of using forms authentication. My problem is with assigning roles. The documents I have read talks about assigning roles in the web.config file. This seems like it would be very tedious to manage. Currenly I have all roles stored in a SQL 2000 DB...
5
1666
by: V. Jenks | last post by:
Using forms authentication, can I control which pages and/or directories a user would have access to or is that only available with Windows authentication? Thanks!
0
2072
by: William F. Zachmann | last post by:
A web site that will run on Windows Server 2003 and IIS 6.0 needs to provide three levels of access, one for the public and two others for two levels of subscribers. This is a port of a prior site that runs on an old version of the Netscape Web server (which manages user authentication and access). The three levels of access are currently served up by three different versions of an ISAPI DLL, written in C++, also managed by the Netscape...
18
6880
by: Rippo | last post by:
Hi I am using role base forms authentication in asp.net and have come across a problem that I would like advice on. On a successful login a session variable is set to identify a user. This is all good as this session variable is used to retrieve data for that user etc. However if I restart the webserver then the users session is lost but the ticket is still active. Therefore the user is not redirected back to the login page.
0
8831
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9325
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9249
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8244
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4607
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4876
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.