DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Securing Your Software Supply Chain with JFrog and Azure
Register Today

Trending

  • Microservices With Apache Camel and Quarkus (Part 3)
  • DevOps vs. DevSecOps: The Debate
  • Decoding eBPF Observability: How eBPF Transforms Observability as We Know It
  • From CPU to Memory: Techniques for Tracking Resource Consumption Over Time

Trending

  • Microservices With Apache Camel and Quarkus (Part 3)
  • DevOps vs. DevSecOps: The Debate
  • Decoding eBPF Observability: How eBPF Transforms Observability as We Know It
  • From CPU to Memory: Techniques for Tracking Resource Consumption Over Time

Forms Authentication - Manual Authentication

Dave Bush user avatar by
Dave Bush
·
Oct. 06, 09 · News
Like (0)
Save
Tweet
Share
9.10K Views

Join the DZone community and get the full member experience.

Join For Free

I’ve had several occasions in the past where I’ve needed to do my own authentication or I’ve needed to add some additional methods to the authentication process.

As easy as Microsoft has made the authentication process, you might think that in order to  manually authentication you’d need to write all of your authentication code manually.  But nothing could be further from the truth.

In fact, most of the time, all you need to do is trap an event handler in the existing login control.

A couple of years ago, I was asked to create a login page that used a web service to authenticate the user.  I also needed to add another form field to the login screen so it became obvious that to do this I’d need to turn the login control into a templated control.

Once this was done it was a simple matter to trap the click event of the login button, authenticate against the web service and then set the authentication cookie for ASP.NET.

Since I can’t show you how to authenticate against the service, your implementation will almost certainly be different, we will skip that section.  But to set the cookie, all we need to do is to revert to the ASP.NET 1.1 way of setting up the login.

if (Request.QueryString["ReturnUrl"] != null)
{
FormsAuthentication.RedirectFromLoginPage (m_tbUsername.Text, persistentCookie);
}
else
{
FormsAuthentication.SetAuthCookie (m_tbUsername.Text, persistentCookie);
Response.Redirect("~/");
}

The first line checks to see if there was a Return URL specified.  If there was we can use the RedirectFromLoginPage API.  Otherwise, we need to set the Authentication Cookie manually and redirect on our  own.

The persistentCookie parameter is true if we want the user to always be logged in.  Otherwise, the login is for the session.

 

authentication

Published at DZone with permission of Dave Bush, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • Microservices With Apache Camel and Quarkus (Part 3)
  • DevOps vs. DevSecOps: The Debate
  • Decoding eBPF Observability: How eBPF Transforms Observability as We Know It
  • From CPU to Memory: Techniques for Tracking Resource Consumption Over Time

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: