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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:46:32+00:00 2026-06-07T16:46:32+00:00

I have a login page and a global page where the user is redirected

  • 0

I have a login page and a global page where the user is redirected to after he logged in.

I need to know if this is a good method for protecting some web files to be accessed if the user is not logged in.

global.aspx code (the protected page where the user is redirected after he logged in)

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Login"] != null)
        {
            if (Session["Login"].Equals("Logged"))
            {
                userName.Text = (string)Session["UserTest"].ToString();
            }
        }
        else
            Response.Redirect("http://localhost:port/Login.aspx");
    }

Login page code:

Session["Login"] = "Logged";
Session["UserTest"] = "Test123";
Response.Redirect("http://localhost:port/Global.aspx");

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-07T16:46:34+00:00Added an answer on June 7, 2026 at 4:46 pm

    I think you should read about forms authentication. And yet another article about it. The code you have written seems fine but my God, you are reinventing a wheel.

    The idea of forms authentication is that the currently authenticated username is stored in an encrypted cookie (unless defined otherwise) and sent along each request. The forms authentication module, once activated, checks for the presence of this cookie on each request and automatically assigns the User property to make it available to all your pages. And if someone attempts to access a protected page, the module simply redirects him to the login page that was configured in web.config. The <location> element in web.config allows you on the other hand to specify which pages/folders of you application require authentication.

    So once you activate forms authentication, here’s how your protected page could look like:

    protected void Page_Load(object sender, EventArgs e)
    {
        userName.Text = User.Identity.Name;
    }
    

    And the Login page (which should not be protected):

    public void Login_Click(object sender, EventArgs e) 
    {
        if (Membership.ValidateUser(userName.Text, password.Text))
        {
            FormsAuthentication.RedirectFromLoginPage(username.Text, false)
        }
        else
        {
            errorLabel.Text = "Invalid credentials";
        }
    }
    

    You might also checkout the Login control that could simplify this even further.

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

Sidebar

Related Questions

I have a Login page that captures User input like this. MD5calc ss =
I have created login page forced login in several pages. Now i need to
I have a login page. When the user enters valid Username and Password another
Scenario: I have a login page which uses ajax to validate a user and
I have a Login.aspx page, and I wanna incude some piece of code in
I have some jQuery code like this: // Called right away after someone clicks
I have a simple ASP.NET page where after the initial page load the user
I have a comment page, and where I have user roles(Global Admin(3), Admin(2), User(1)),
Normally we have login page with username, password filed and signin button. Using the
I have a login page (an activity in Android), during which I run an

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.