473,802 Members | 2,031 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

When session is invalid, how to redirect user to the login page

I have a asp.net app. When session is invalid, how to redirect user to the
login page? I don't want to add the code to redirect user to the login page
into every page.

Thanks,
-Billy
Nov 11 '08 #1
3 3237
this is what the global.asax is for. PostAcquireRequ estState would be a
good event.

-- bruce (sqlwork.com)

Billy Zhang wrote:
I have a asp.net app. When session is invalid, how to redirect user to the
login page? I don't want to add the code to redirect user to the login page
into every page.

Thanks,
-Billy
Nov 11 '08 #2
Hi Billy,

Are you using custom forms authentication which is based on some
information stored in session? Anyway, if you do need a central place
where you can check session state and redirect request, you can consider
the approach Bruce introduced(use some global events ).

And instead of using global.asax, you can also write a custom httpmodule to
hook any of the global events in ASP.NET. Here are two kb articles
introduce this:

#INFO: ASP.NET HTTP Modules and HTTP Handlers Overview
http://support.microsoft.com/kb/307985

#How To Create an ASP.NET HTTP Module Using Visual C# .NET
http://support.microsoft.com/kb/307996

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we

can improve the support we provide to you. Please feel free to let my
manager know what you think of

the level of service provided. You can send feedback directly to my manager
at: ms****@microsof t.com.

=============== =============== =============== =====
Get notification to my posts through email? Please refer to

http://msdn.microsoft.com/en-us/subs...#notifications.

--------------------
>From: =?Utf-8?B?QmlsbHkgWmh hbmc=?= <ht****@noemail .noemail>
Subject: When session is invalid, how to redirect user to the login page
Date: Mon, 10 Nov 2008 19:04:00 -0800
>I have a asp.net app. When session is invalid, how to redirect user to
the
>login page? I don't want to add the code to redirect user to the login
page
>into every page.

Thanks,
-Billy
Nov 11 '08 #3
You may also consider using a base page. Basically, create a class
that inherits from System.Web.UI.P age and have all of your aspx pages
inherit from that class. You can than put your session check code in
there.

http://aspnet.4guysfromrolla.com/articles/041305-1.aspx

Nov 12 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
26894
by: deko | last post by:
I'm trying to create a very basic login page that will redirect a logged in user to a secure page. I set the session_start variable at the top of the login page, then redirect to securePage.php if the user enters the right credentials. The redirect works, but apparently $HTTP_SESSION_VARS is not getting set because I cannot view securePage.php. Am I setting $HTTP_SESSION_VARS correctly? My guess is I'm missing something elementary. ...
9
2408
by: Brian Burgess | last post by:
Hi all, Anyone know of any issues with setting the value of a Session object to the value of a submitted form item via 'Session("mySessionObj")=Request.Form("myFrmElem")' ? In my case the Session object gets set fine. But when the user links to another page, the value of the session object is EMPTY. thanks in advance..
3
2922
by: Geoff Winsor | last post by:
Hi, I am experiencing a problem with recalling a session variable which stores whether a person is logged in to a "members only" section of a website. This area of the site has been working flawlessly for a couple of years under Windows 2000 server but now is very inconsistent following a recent upgrade to Windows server 2003. Following a login, the login info is passed to this asp page that checks an Access database for the user name and...
12
43199
by: Geigho | last post by:
Setting session timeout in web.config file does not seem to have any effect. Any explanation or suggestion will be appreciated.
3
4571
by: Carpe Diem | last post by:
Hello I have an aspx page that loses Session("user") value after a few minutes even after I set <sessionState mode="InProc" cookieless="false" timeout="300"> in web.config and wrote function Session_Start() { Session.Timeout = 3000; } in global.asax
12
6995
by: ACaunter | last post by:
Hi all, I was wondering how i could write some code which would automatically open the Login Page once the session has expired? -- AdamPC@hotmail.com
2
2292
by: Hillary Hill | last post by:
I have a login page written in ASP. Once the user logs in to the system, by clicking the certain link they can navigate to the purchase module written in ASP.Net. In the purchase module the user can logout. Once the user logs out I am calling the Session.Abandon() and redirecting the user to the login page written in asp application. How to make sure the ASP part of the application abandons the session.
18
6885
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.
3
4343
by: =?Utf-8?B?RHVrZSAoQU4yNDcp?= | last post by:
The majority of pages on our site need authentication (forms auth against the aspnetdb database). I created an '~/auth' folder with its own config file forcing authentication for any pages in the folder. The default.aspx sits in the root folder and just does a Response.Redirect to an ~/auth/home.aspx page. The config forces authentication, which is carried out by ~/pub/login.aspx which has a standard asp:login control. I set up the...
0
10536
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10063
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
9114
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
6838
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
5494
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
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4270
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
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2966
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.