hello,
I am using forms authentication and I would like that my authentication
cookie expires after let say 1 minutes (just for the exemple).
When I log in in my longon page, the user has to input a username, password
and the click a button to effectively login.
In the event handler for my button I have the following code:
// create authentication ticket and encrypt it
FormsAuthentica tionTicket authTicket = new FormsAuthentica tionTicket(1,
TextBoxUserName .Text, DateTime.Now, DateTime.Now.Ad dMinutes(1), false,
roles);
string encryptedTicket = FormsAuthentica tion.Encrypt(au thTicket);
// Create a cookie and add the encrypted ticket to the cookie as data.
HttpCookie authCookie = new HttpCookie(Form sAuthentication .FormsCookieNam e,
encryptedTicket );
// Add the cookie to the outgoing cookies collection.
Response.Cookie s.Add(authCooki e);
You can notice in the constructor of my authentication ticket the presence
of DateTime.Now.Ad dMinutes(1) which effectively says that if the user did
not made any other requests within 1 minute, his cookie will expires and he
will have to long in again. That works FINE.
Now I want to add role authorization in my system and I read a Microsoft
article that tells me to implement Application_Aut henticateReques t(Object
sender, EventArgs e) in global.asax
I dot it and follow the MS guidelines which mainly consist of creating a
Principal object and assign it to the Context.User property. Then in can get
that User property from anywhere in my application and verify if the user as
the role authorization he needs to view the webpage.
here is the code :
string cookieName = FormsAuthentica tion.FormsCooki eName;
HttpCookie authCookie = Context.Request .Cookies[cookieName];
if(authCookie== null)
{
return;
}
// extract and decrypt the authentication ticket from the forms
authentication cookie
FormsAuthentica tionTicket authTicket = null;
try
{
authTicket = FormsAuthentica tion.Decrypt(au thCookie.Value) ;
}
catch(Exception ex)
{
return;
}
if (authTicket==nu ll)
{
return;
}
// When the ticket was created, the UserData property was assigned a
// pipe delimited string of role names.
string[] roles = authTicket.User Data.Split(new char[]{'|'});
// Create an Identity object
FormsIdentity formsIdent = new FormsIdentity(a uthTicket);
// This principal will flow throughout the request.
GenericPrincipa l principal = new GenericPrincipa l(formsIdent, roles);
// Attach the new principal object to the current HttpContext object
Context.User = principal;
Everything is working except that now with this piece of code in my
global.asax file, the authentication cookie never expires anymore... Why ?
Is there anyone who can explain me how this can happen and how I can solve
the problem?
Best regards and thank you in advance for any help
Francois 0 1239 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Rob Douglass |
last post by:
Hi all,
I have a site that is compeletely restricted by form authentication.
In the case where a user's cookie expires and then they click on the
logout button on the site, the authetication process is forcing them
to login again so that they can log out.
I've been trying to use
"HttpContext.Current.User.Identity.IsAuthenticated" as the first piece
of code in the "Page_Load" routine, but the server is redirecting the
|
by: Ben S |
last post by:
framework 1.1
in our webapp, we are using forms authentication.
=================
Auth Section from web.config
=================
<authentication mode="Forms">
<forms name="loginauth" path="/" loginUrl="loginauth.aspx"
|
by: ElmoWatson |
last post by:
I tried on the Security newgroup, as well as other places, and haven't
gotten an answer yet - - I'm pulling my hair out over this one.
I'm trying to get Forms Authentication working.....I can get any requested
page to automatically go to the Login.aspx page, AND, the ReturnURL
querystring is correct in the address bar, but no matter what, I can't get
it, once the user is authenticated, to redirect to the new page. It ALWAYS
refreshes the...
|
by: Do |
last post by:
Hi,
What's the default expiration for forms authentication?
If I hit refresh, will i get redirected to a login page(if the time has
expired)?
Thanks,
Do
|
by: Martin |
last post by:
Dear fellow ASP.NET programmer,
I stared using forms authentication and temporarily used a <credentials> tag
in web.config. After I got it working I realized this wasn't really
practical. I cannot write to web.config so I cannot dynamically update the
credentials while the site is up. Since the
FormsAuthentication.Authenticate() method's documentations claims the
following:
"Attempts to validate the credentials against those contained...
| |
by: David W. Simmonds |
last post by:
I have a form that will prompt for a user name/password. In VS.NET, I have
the protected form in a folder named Admin. I have a Web.config file in that
folder as well. It contains the following section:
<authorization>
<deny users="?" />
<allow users="*" />
</authorization>
In the root folder where the other forms are located I have a Web.config
|
by: AVance |
last post by:
Hi,
I've come across this scenario in ASP.NET 1.1 with forms authentication
where the forms auth doesn't seem to timeout correctly, nor redirect to the
login page.
I have done some testing, and I believe I've found a solution, but I
would like some insight from Microsoft on whether the code I've implemented
is correct, and why it is even working.
Here is my scenario:
|
by: Simon Harvey |
last post by:
Hi All,
I'm hoping somebody could help me with the following problem.
I'm using forms authentication and the user is getting authenticated no
problem. Once authenticated the user can look at all the appropriate
pages and so on.
When the user is inactive for a set period of time, I want their
authentication ticket to expire. As I understand it, the next time the
|
by: Peter Bradley |
last post by:
We are in the process of designing our first ASP.NET 2.0 application and
have discovered that Forms Authentication works completely differently in
ASP.NET 2.0.
For a number of reasons, we cannot use the standard login component supplied
with ASP.NET 2.0 (e.g. we need full control of the look and feel - including
using CSS and not tables for layout - and we need to be able to handle the
authentication cookie ourselves rather than let a...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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,...
| |
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |