?
Solved

in asp.net is it possible to run a code before opening any pages?

Posted on 2013-10-23
5
Medium Priority
?
239 Views
Last Modified: 2013-10-24
I do not want anyone to be able to open any pages on the website before it could run the code to see if the person is logged in and if not send them to log page.

I already have my own log in process and not using the built in asp.net login.  Do not want to use it either.


Currently I have a code inside all the pages and it executes before the page opens.  I am just wondering if there was even a better way and I could execute a code prior to opening a page.
0
Comment
Question by:goodk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39595592
If you have not already, add a Global Application Class item to your project:

Screenshot
Then write your code in the Application_BeginRequest handler:

Screenshot
0
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 2000 total points
ID: 39595800
@kaufmed likely has your answer.  But you should know that the very first thing that happens on a web site is that the client sends a request for a page.  There are a lot of things you can do before you send a response and the page content.  One of them is checking for a login by whatever method you are using.  A page request always includes the cookies that have been set by your site so if the login is part of that, you can check it before you respond.
0
 

Author Comment

by:goodk
ID: 39599013
Hi DaveBaldwin,

Do you have any direct example of staying logged in by using cookies.  I am also having an issue with the session timing out.
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 39599072
No, I don't have an example.  But sessions are supposed to time out when they are not being used.  I don't know what the timeout period is for ASP.NET sessions but you might be able to extend it.  If you want to bypass the session timeouts, you will need to either avoid using session variables or store session info or data in a database.  And you would need to write your own login cookies.  Make sure that any data you put there is not personal private data like usernames and passwords.
0
 

Author Closing Comment

by:goodk
ID: 39599091
thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month8 days, 1 hour left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question