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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:02:06+00:00 2026-05-23T09:02:06+00:00

I seem to cant set up an authentication system in asp.net I have code

  • 0

I seem to cant set up an authentication system in asp.net
I have code for a login system:

protected void btnlogin_Click(object sender, EventArgs e)
{
    PageUser myUser = new PageUser();
    if (myUser.AuthenticateUser(txtUsername.Text, txtPassword.Text))
    {
        // entry found

        HttpCookie myCookie;

        DateTime now = DateTime.Now;

        myCookie = new HttpCookie("UserName");
        myCookie.Value = myUser.UserName;
        myCookie.Expires = now.AddMinutes(30);
        Response.Cookies.Add(myCookie);

        myCookie = new HttpCookie("LoginID");
        myCookie.Value = myUser.UserLoginID.ToString();
        myCookie.Expires = now.AddMinutes(30);
        Response.Cookies.Add(myCookie);

        lblResult.Visible = false;

        FormsAuthentication.SetAuthCookie(myUser.UserName + " " + myUser.UserLoginID.ToString(), true);

        Response.Redirect("AdminView.aspx");
    }
    else
    {
        // entry not found
        lblResult.Text = "<b>Invalid logon attempt<b>";
        lblResult.ForeColor = System.Drawing.Color.FromName("Red");
        lblResult.Visible = true;
    }
}

The authentication method works fine, but when I do not login it still lets me redirect twords the AdminView even though the person didnt login.
Code I am having difficulty with:

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {

    }
    string userName = "";
    string[] splits;
    try
    {
        if (this.Page.User.Identity.IsAuthenticated)
        {
            splits = this.Page.User.Identity.Name.Split(new char[1] { ' ' });
            userName = splits[0] + " " + splits[1];

        }
        else
        {
            Response.Redirect("default.aspx");
        }
        txtLoggedInUser.Text += " - " + userName;
    }
    catch
    {
        Response.Redirect("default.aspx");
    }
}

I am not sure how to write this code so it would redirect a person back to the login page when they try to visit the admin page.

  • 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-23T09:02:07+00:00Added an answer on May 23, 2026 at 9:02 am

    To restrict an unauthenticated user to the AdminView.aspx page, you have to add below into the configuration section of the web.configfile.

    <location path="AdminView.aspx">
    <system.web>
        <authorization>
            <deny users="?"/>               
        </authorization>
    </system.web>
    

    <deny users="?"/> mean’s the unauthenticated user will not be able to access the file/folder AdminView.aspx

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

Sidebar

Related Questions

Hey I have a session object I just cant seem to destroy or set
I have the following composable dml and I cant seem to set it working.
I cant' seem to work uploadify on ASP.NET MVC3, I searched a lot and
I'm trying to set up the swiz framework in flex but cant seem to
I have one application which uses the standard .NET forms authentication cookie, now I
This I cant seem to figure out. In a nutshell I have a webpage
I have a bit of an easy question which i cant seem to figure
I have found this script and cant seem to figure out why it throws
I cant seem to find a way to set a secure cookie in expressjs
I have looked at similar questions and cant seem to get the answer 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.