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 6324159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:39:09+00:00 2026-05-24T16:39:09+00:00

I have an ASP .NET web application (runs only on the Intranet) where I

  • 0

I have an ASP .NET web application (runs only on the Intranet) where I am using a simple user authorization model. I have a table called tblApplicationAccess which has TWO fields – UserID and AccessLevel.

For example,
UserID: John.Smith, Access Level: 2

(1 – General Access, 2 – Data Entry Access, 3 – Super User, 4 – Developer Access)

I am using the Session_Start event in global.asax to authorize the user. Here is the code,

protected void Session_Start(object sender, EventArgs e)
    {
        string strUserID = User.Identity.Name.Substring(5);
        bool isAllowedToView = false;

        // UtilityClass is a root level class with various methods that I use throughout the application. 
        // QUESTION: Could this be the problem? Since it is at root level (alongside all the pages), could it be the case that this resource isn't checked for user access?  

        UtilityClass.StrCurrentSessionID = this.Session.SessionID;

        // Add a row to BLSC_tblSession
        int nRowsReturned;
        string strConnectionString = UtilityClass.GetConnectionString("My Application");
        string strQueryStartSession = "INSERT INTO BLSC_tblSession " +
                                      "(SessionID, UserID, SessionStatus, StartTime, EndTime) " +
                                      "VALUES ('" + this.Session.SessionID + "', '" + User.Identity.Name.Substring(5) + "', 'Active', '" + DateTime.Now + "', '" + DateTime.Now.AddDays(1) + "')";
        SqlConnection connStartSession = new SqlConnection(strConnectionString);

        if (connStartSession != null)
        {
            try
            {
                connStartSession.Open();
                SqlCommand sqlStartSession = new SqlCommand(strQueryStartSession, connStartSession);

                nRowsReturned = sqlStartSession.ExecuteNonQuery();
                if (nRowsReturned == 0)
                    throw new Exception("Session could not be started.");
                else
                {
                    // Authorize User
                    // Check if user has access to the application. If not, redirect to UnauthorizedAccess.aspx
                    // Check for access level 1.
                    // IMPORTANT: For Dev server change access level to 4.
                    isAllowedToView = UtilityClass.CheckUserAccess(strUserID, 1);
                    if (isAllowedToView == false)
                    {
                        UtilityClass.WriteToLog("Application Access Denied: UserID - " + strUserID, 1);
                        Response.Redirect("Some URL");
                    }
                    else
                    {
                        // Browser detection
                        string strBrowserName = Request.Browser.Browser;
                        if (strBrowserName != "IE")
                        {
                            UtilityClass.WriteToLog("Non-supported browser usage detected: UserID - " + strUserID + ", Browser - " + strBrowserName, 0);
                            Response.Redirect("Some other URL");
                        }
                    }
                }
                connStartSession.Close();

            }
            catch (SqlException SqlEx)
            {
                UtilityClass.HandleError("Global.asax", "Session_Start", SqlEx.Message);
            }
            catch (Exception Ex)
            {
                UtilityClass.HandleError("Global.asax", "Session_Start", Ex.Message);
            }
            finally
            {
                if (connStartSession != null)
                    connStartSession.Close();
            }
        }
    }

UtilityClass.CheckUserAccess

public static bool CheckUserAccess(string UserID, int RequiredAccessLevel)
    {
        bool bReturn = false;
        object TemporaryPlaceHolder;
        int nUserAccessLevel = 0;
        string strQueryCheckUserAccess = "SELECT AccessLevel " + 
                                         "FROM BLSC_tblApplicationAccess " +
                                         "WHERE UserID = '" + UserID + "'";
        string strConnectionString = GetConnectionString("My Application");
        SqlConnection connCheckUserAccess = null;
        try
        {
            if (strConnectionString != String.Empty)
            {
                connCheckUserAccess = new SqlConnection(strConnectionString);
                connCheckUserAccess.Open();

                if (connCheckUserAccess != null)
                {
                    SqlCommand sqlCheckUserAccess = new SqlCommand(strQueryCheckUserAccess, connCheckUserAccess);

                    TemporaryPlaceHolder = sqlCheckUserAccess.ExecuteScalar();
                    if (TemporaryPlaceHolder != DBNull.Value && TemporaryPlaceHolder != null)
                    {
                        nUserAccessLevel = Convert.ToInt32(TemporaryPlaceHolder);
                        if (nUserAccessLevel >= RequiredAccessLevel)
                            bReturn = true;
                        else
                            bReturn = false;
                    }
                    else
                        bReturn = false;
                }
                connCheckUserAccess.Close();
            }
        }
        catch (SqlException SqlEx)
        {
            HandleError("UtilityClass.cs", "CheckUserAccess", SqlEx.Message);
        }
        catch (Exception Ex)
        {
            HandleError("UtilityClass.cs", "CheckUserAccess", Ex.Message);
        }
        finally
        {
            if (connCheckUserAccess != null)
                connCheckUserAccess.Close();
        }
        return bReturn;
    }

The Problem:
My application does not load in the production environment.

The application runs using Windows Authentication. To be precise, we have DomnainName\ApplicationServer$ accessing SQL Server and not individual users.

My Question:

If I want to check application access using my current model and the global.asax events, where is the best place to put it? Am I doing something grossly wrong here? I need to write to the session table for logging events and cannot use role-based authentication that ASP .NET provides.

  • 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-24T16:39:09+00:00Added an answer on May 24, 2026 at 4:39 pm

    From my perspectives SessionStart looks as a good place to do such things.
    At first try to figure out why it does not load in production and see whether any unhandled exceptions are occur

    1. Try out add logs in the protected void Application_Error(Object sender, EventArgs e)
      in the global.asax file
    2. Subscribe for HttpApplication.Error
    3. See Windows EventLog
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a fairly simple CRUD web application (C#/ASP.NET) that runs fine in Firefox,
I have an ASP.NET web application the entire site is browsed over HTTPS using
I have an asp.net web application written in C# using a SQL Server 2008
I have a asp.net web application and I'm using cache (HttpRuntime.Cache) to save some
I have an ASP.NET web application that is using forms authentication. Everything is configured
I have an ASP.NET web application project which references another project called ModusCore (or
I have an ASP.net web service that I'm using for a web application which
I have a asp.net web application that runs locally and opens docx files in
I have a applet that runs with no issue in asp.net web application ...
We have an asp.net 4.0 (integrated mode) web application that runs on iis 7.5

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.