Solved

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

Posted on 2013-10-23
5
227 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
  • 2
  • 2
5 Comments
 
LVL 74

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 82

Accepted Solution

by:
Dave Baldwin earned 500 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 82

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now