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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:54:49+00:00 2026-06-04T02:54:49+00:00

Hey I am creating a forum where users can login and post ocmments in

  • 0

Hey I am creating a forum where users can login and post ocmments in a forum, I want the username as a session variable so I can get it when they post a comment and insert the username in the db and also to display a hello user message.

Below is my login code:

protected void Button1_Click(object sender, EventArgs e)
{
    DataSet ds = new DataSet();
    localhost.Service1 myws = new localhost.Service1();
    ds = myws.GetUsers();
    foreach (DataRow row in ds.Tables[0].Rows)
        if (txtusername.Text == System.Convert.ToString(row["username"]) &&
        txtpassword.Text == System.Convert.ToString(row["password"]))
        {
            System.Web.Security.FormsAuthentication.RedirectFromLoginPage(txtusername.Text, false);
        }
        else
            Label3.Text = "Invalid Username/Password";
}

Do I declare the session variable here?

Like:

Session["username"] = "username";

Also not sure what to type to get the value username from the db

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-06-04T02:54:50+00:00Added an answer on June 4, 2026 at 2:54 am

    You don’t need to use a session. Once you call the FormsAuthentication.RedirectFromLoginPage method, inside the target page you could access the currently connected user from the authentication cookie that was emitted by this method using User.Identity.Name.

    protected void Page_Load(object sender, EventArgs e)
    {
        if (User.Identity.IsAuthenticated)
        {
            string username = User.Identity.Name;
            // ...
        }
    }
    

    To learn more about how Forms Authentication works in ASP.NET I invite you to read the following article.

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

Sidebar

Related Questions

Hey guys, I'm creating a comment box and I want to do two stuff
Hey guys, I'm creating a DLL in C++ and I want it to be
Hey guys I'm creating a jquery plugin and I'm trying to either get the
I am creating an image viewer, and I want add an entry to Hey
Hey I am a bit stuck at the moment, I am creating a forum,
Hey all, I am creating a login script that in one step, enters the
hey I'm creating an app with two switches on it that change the background
Hey this is my first question on this website. Im creating a webpage for
Hey all, I want to change a value in a table (in a mysql
Hey I have some problems creating my query into doctrine: My sql query looks

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.