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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:43:52+00:00 2026-06-09T20:43:52+00:00

I have a problem with my class below: Iam tring to hold UserID without

  • 0

I have a problem with my class below:

Iam tring to hold UserID without Session and of course Querystring, I thought i can store it in my UserClass.

So when i try to get the ID for example: Default.aspx:

MyUserClass  userclass=new MyUserClass();//global

//(at button click)
userclass.GetUser(TextBox1.Text, TextBox2.Text);
int UserID=userclass.UserID;

when i reload the page UserID=0 that i get ok. then i tried to use a static variable for that. example:

static MyUserClass  userclass=new MyUserClass(); //global
//(at button click)
    userclass.GetUser(TextBox1.Text, TextBox2.Text);
    int UserID=userclass.UserID;

i get the ID when i also reloaded the page, but when somebody else logins , my ID changes with the other ID

how can i do that with this way or i mean with properties?

The class is:

public class MyUserClass
{
    private  int _UserID;
    public  int UserID
    {
        get
        {
            return _UserID;
        }
    }


    public int  GetUser(string UserName, string Pass)
    {
        int UserID=0;
        try
        {

            DB.conn.Close();

            SqlCommand command = new SqlCommand("pUserkontrol", DB.conn);
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.AddWithValue("@puserName", UserName);
            command.Parameters.AddWithValue("@pPass", Pass);
            DataTable dt = new DataTable();
            DB.conn.Open();
            SqlDataReader dr = command.ExecuteReader();

            dt.Load(dr);
            DB.conn.Close();
            if (dt.Rows.Count < 1)
            {

            }

            else
            {
                foreach (DataRow datarow in dt.Rows)
                {
                    _UserID = Convert.ToInt32(datarow["UserID"]);
                    //UserID = _UserID;



                }

            }
        }
        catch (Exception ex)
        {



        }



        return UserID;


    }
}
  • 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-06-09T20:43:53+00:00Added an answer on June 9, 2026 at 8:43 pm

    The web is stateless by nature and as such each new request is “overwriting” the UserId value as it stands there is nothing to tie back the request back to your class. You need to use some sort of storage mechanism. As you’ve discounted using session and querystring I would suggest rolling your own lightweight ASP.NET membership provider and implementing IIdentity and IPrincipal and creating an Authentication Ticket (Cookie) through the provider in order to persist your post-login details (userId). Take a look at Brady Gasters blog and the comments posted there for how to do this.

    http://www.bradygaster.com/custom-authentication-with-mvc-3.0

    This post implements the membership in MVC 3 using Sessions however the comments and other links on the page show how to manipulate the code and use cookies auth. Implementing it in Web Forms (if youre using webforms) should also be fairly straightforward too.

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

Sidebar

Related Questions

I have got a memory leak problem in the example below(u can download the
Good day, I have the following problem: class B extends class A and methods
I have a design problem: Question class: have a question and answer (String) TextQuestion
I have a problem with ViewHolder class. I use ViewHolder to improve my List
I have problem organizing my unittest based class test for family of tests. For
I have a problem to test my non activity-class which need the context of
I have a problem in calling a template class I have. I declared a
i have a problem calling multiple instance of a class that i have coded
I have the problem that my view controller class has too many delegates and
I have a problem with getting a class from an external .jar file. I

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.