[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2013-10-23
5
Medium Priority
?
241 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 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

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 …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month20 days, 6 hours left to enroll

872 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