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

  • Home
  • SEARCH
  • 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 6960459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:24:17+00:00 2026-05-27T15:24:17+00:00

I want save users’s IPs and activity in a table named logPublic,I want when

  • 0

I want save users’s IPs and activity in a table named logPublic,I want when a unAthenticated user try to access a speacial folder e.g Admin folder i can add a record in logpublic table that it have some fields for e,g : ID,IP,Activity,datetime .after that unathenticated user will be lock utomatically

I am use below code in Load_Page Event of masterpage in Admin folder:

$public partial class Admin : System.Web.UI.MasterPage 
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        if (!HttpContext.Current.User.Identity.IsAuthenticated)
        {
            Session["IsBlocked"] = true;
            string ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
            HttpContext.Current.Session["UserIP"] = ip;
            HttpContext.Current.Session["Activity"] = HttpContext.Current.Request.Url;
            HttpContext.Current.Session["DateTime"] = System.DateTime.Now;
        }
        else
        {
            if(! HttpContext.Current.User.IsInRole("Admin"))
            {

            Session["BlockUser"] = true;
            string ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
            HttpContext.Current.Session["UserIP"] = ip;

          }
        }


    }
}


$namespace StoreProject.Data
{
    public class CustomSecurityModule :IHttpModule
    {

     storedbEntities StoreEnt = new storedbEntities();
    public void Dispose()
    {
        throw new NotImplementedException();
    }

    public void Init(HttpApplication context)
    {
        //throw new NotImplementedException();
        context.BeginRequest += new EventHandler(this.app_DoSecuriy);
    }

    private void app_DoSecuriy(object sender, EventArgs e)
    {
        // Create HttpApplication and HttpContext objects to access
        // request and response properties.
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;

       storedbEntities StoreEnt = new storedbEntities();

        if (context.Session["BlockUser"]!= null &&  Convert.ToBoolean(context.Session["BlockUser"])== true)
        {

                logPrivate Log = new logPrivate()
                 {
                     Username = context.User.Identity.Name,
                     IP = context.Session["UserIP"].ToString(),
                     Enter = System.DateTime.Now,

                 };
                StoreEnt.logPrivates.AddObject(Log);
                StoreEnt.SaveChanges();
                context.Response.Redirect("~/UnAuthorizedAccess.aspx");


        }
        //ublock != null && bool.TryParse(ublock.ToString(),out isblocked) && isblocked
        else if ( context.Session["BlockPublick"] != null 
                 && System.Convert.ToBoolean(context.Session["BlockPublick"]) == true)
        {

            LogPublic newLog = new LogPublic()
            {

                IP = context.Session["UserIP"].ToString(),
                Activity = context.Session["Activity"].ToString(),
                Enter = Convert.ToDateTime(context.Session["DateTime"])

            };
            StoreEnt.LogPublics.AddObject(newLog);
            StoreEnt.SaveChanges();

            context.Response.Redirect("~/UnAuthorizedAccess.aspx");
        }


        }
    }
}

but when i run my application website ,i get an error from httpmodule :Object reference not set to an instance of an object. error in below line

if (context.Session["BlockUser"]!= null 
  &&  Convert.ToBoolean(
        context.Session["BlockUser"])== true)

i dont have any record in LogPublic table or logPrivate table when i want visit a page in Admin Folder
please guide me

thanks

  • 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-27T15:24:18+00:00Added an answer on May 27, 2026 at 3:24 pm

    Module’s BeginRequest is too early to access the Session object as it hasn’t been yet created by the ASP.NET Pipeline. You’d have to move your logic to one of later events in the processing pipeline (after PostAcquireRequestState)

    http://msdn.microsoft.com/en-us/library/ms178473.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to save a balance of user, in the user table . the
I want to setup a table that can: Save the data on the user's
I want to save permissions for both individual users, and user groups. In my
My model: class Sample(models.Model): users = models.ManyToManyField(User) I want to save both user1 and
I want to register user clicked on ads and save users info to database
I want to open a save file dialog, have the user enter a filename,
i want to save logged in users actions so when they visit the page
I want to save an image as binary to the users localhost for future
I'm wondering whats the best folder structure for a web application to save users
I want to save some info in the Session when the users successfully logins

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.