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

The Archive Base Latest Questions

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

I am trying to implement authentication using jQuery and Forms Authentication on an ASP.NET

  • 0

I am trying to implement authentication using jQuery and Forms Authentication on an ASP.NET MVC 3 web service. The idea is that I’ll do a jQuery AJAX post to the web service, which will do Forms Authentication and return a cookie or token, and with each data access call, my web application (jQuery) will use that cookie or token.

What I have –

I have the AJAX call to the ASP.NET Web service set up, and I have the web service set up as follows:

public ActionResult Login(string userName, string password, bool rememberMe, string returnUrl)
{

    if (ModelState.IsValid)
    {
        if (Membership.ValidateUser(userName, password))
        {
            return Json(FormsAuthentication.GetAuthCookie(userName, rememberMe), JsonRequestBehavior.AllowGet);

        }
        else
        {
            return Json("Authentication Failed", JsonRequestBehavior.AllowGet);
        }
    }
}

This is working so that if I make the AJAX call with correct credentials, I am returned a cookie in JSON, and if not, I’m returned the auth failed string.

What I don’t know – What to do with the JSON cookie once I receive it back. I can store this in HTML5 local storage, but I don’t know what part of it (or the whole thing) to send back with my data access calls, and how to interpret it and check the cookie on the web service side. If I shouldn’t be using cookies, is there a way to generate and use a token of some kind?

  • 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-07T02:07:09+00:00Added an answer on June 7, 2026 at 2:07 am

    For anyone else who happens to come across, here’s how I solved it:

    I realized that sending the cookie back via JSON was not necessary. By using FormsAuthentication.SetAuthCookie, an HTTP Only cookie is set, which gets automatically sent with AJAX calls. This way, the server is the only one responsible for the Auth cookie, and can verify the authentication with Request.IsValidated.

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

Sidebar

Related Questions

I'm trying to implement authentication using jquery to make an ajax request to a
I'm trying to implement a remember me feature using ASP.NET MVC. It uses a
ASP.NET MVC3 Razor project Trying to implement OpenID using http://weblogs.asp.net/haithamkhedre/archive/2011/03/13/openid-authentication-with-asp-net-mvc3-dotnetopenauth-and-openid-selector.aspx I've edited the openid-en.js
I am trying to implement windows authentication in my ASP.NET MVC2 application. I've followed
I am using form-login for security and I am trying to implement an authentication
I'm trying to implement Facebook authentication into my web project. I've managed to get
I 'm trying to implement user authentication and authorization using roles table, user table
I am trying to write an ASP.NET MVC application which is a frontend to
Here's what I'm trying to do. We have a SSO authentication service that other
I'm trying to implement a transient oAuth authentication for a web app I'm creating.

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.