Solved

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

Posted on 2013-10-23
5
231 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 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 83

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 83

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

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…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

777 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