Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6994297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:52:28+00:00 2026-05-27T19:52:28+00:00

This is possibly very lame question and I lack knowledge about ASP.Net. In this

  • 0

This is possibly very lame question and I lack knowledge about ASP.Net. In this case a link to an article explaining would be very welcome.

I’m working on web-site on ASP.NET with C# as codebehind. My current project involves developing few pages with very similar functionality and a many functions are the same. For example

private void PermissionCheck()
{
    if (null == Session["UserID"] ||
        null == Session["ProjectID"] ||
        null == Session["AssetID"] ||
        null == Session["ProjectName"])
    {
        Response.Redirect("~/Login.aspx");
    }
 }

Would be the same on 2 pages. Some other things are the same as well. I would like to put this into common base class. But there are other functions that don’t really belong to pages at all:

private string GetAttachmentTempPath()
{
    return Request.PhysicalApplicationPath + WebConfigurationManager.AppSettings.Get("AttachmentsTempFolder");
}

I would like to move this into Attachment class, but to get the physical path of the application, I need to pass in Request object into that method, which is not really nice, as it couples Attachment class with Page.Request object.

Is there any way to move these functions somewhere else without needing to pass Page.Request objects around??

p.s. The appliction is huge, and there is no scope to change the entire architecture.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:52:29+00:00Added an answer on May 27, 2026 at 7:52 pm

    For your permission thing you could make a base page class:

    class BasePage : Page
    { 
       ...
       protected override OnInit() {
         // do check here
       }
    }
    

    Now you can implement your page like this class MyOtherPage : BasePage { ... }
    The OnInit gets executed everytime your MyOtherPage gets loaded.

    You can see a complete page lifecycle here: Link

    For your other problem: Consider to implement a global available static tool class

    Update

    A good approach for making things like web.config easier to access is a Singleton. In asp.net a singleton is only created once and lives until the asp worker process gets stopped . So this values are shared across the whole asp.net application. This is also good for storing data in a global context that you dont want to get out of your database or file anytime a user makes a page request (for example a version number or things like that)

    Update 2

    To access the request without passing it to every function, use this:

    HttpContext.Current.Request
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I apologise in advance if this question isn't very specific. Would it be possible
This is more of a general question about which direction would be a better
My programming knowledge is very limited, I would really appreciate any help on this
I know this is quite possibly a lame question, but I've pulled three consecutive
This is a very general question: I was wondering whether it is possible to
this may be a very simple question, but is it possible to force a
Ok, this is possibly borderline-subjective, but I wonder where one would put a simple
This could quite possibly be the dumbest question ever asked. Our client wants us
Bear with me, this is possibly a very specific problem we've encountered here: We
I understand that this is a very broad question, but I was very curious

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.