Solved

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

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

717 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