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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:37:45+00:00 2026-05-18T06:37:45+00:00

in my asp.net mvc project i added facebook authentication to my project. I also

  • 0

in my asp.net mvc project i added facebook authentication to my project. I also save the facebook users in my database too. I have default asp.net authentication system for my site.
When a facebook user give permission to my facebook application i get facebook user information like name,id and save them to my User table in my database, also give them a new guid for Id column. Then set them authenticated like below

public ActionResult FbInit()
    {
        FacebookApp app = new FacebookApp();

        if (app.Session != null)
        {
            dynamic parameters = new ExpandoObject();
            parameters.fields = "id,name";
            dynamic result = app.Api("me", parameters);

            string id = result.id;
            string name = result.name;

            using (TestDbEntities context = new TestDbEntities())
            {
                AuthTestAjax.Models.User newUser;
                if (null == (newUser = context.Users.Where(p => p.FbId == id).FirstOrDefault()))
                {
                    newUser = new User();
                    newUser.Id = Guid.NewGuid();
                    newUser.Name = name;
                    newUser.FbId = id;
                    context.AddToUsers(newUser);
                    context.SaveChanges();
                }

                System.Web.Security.FormsAuthentication.SetAuthCookie(newUser.Id.ToString(), false);
            }

        }


        return Json("");
    }

-I make persistent cookie false because i dont know when they will logout from facebook.

When user comes again to my site (he also login facebook), i want him to be authenticated. But how can i do that ?

I am trying to set HttpContext.Current.User but i am not sure that i am on the right way, help me about this situation.

I am trying this.

        public ActionResult AuthBox()
    {
        if (HttpContext.User.Identity.IsAuthenticated)
            return View("AuthBox");

        FacebookApp app = new FacebookApp();

        if (app.Session != null)
        {
            HttpContext.User   // <== Can I set this here to authenticate user?
            return View("AuthBox");
        }

        return View("AnonyBox");
    }
  • 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-18T06:37:46+00:00Added an answer on May 18, 2026 at 6:37 am

    You will need to do FormsAuthentication.SetAuthCookie again when your app identifies the facebook user.

            FacebookApp app = new FacebookApp();
    
            if (app.Session != null)
            {
                FormsAuthentication.SetAuthCookie(app.Session.Username /*Or wherever you get it*/, false);
                return View("AuthBox");
            }
    

    You cannot set HttpContext.User manually.

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

Sidebar

Related Questions

I have an ASP.NET MVC application with a separate project added for tests. I
I have a Code folder in my asp.net mvc web project, I added a
I have an Asp.Net MVC project. I added login with Google button. It appears
I created a default ASP.net MVC project. In the Master page I have the
In my ASP.NET MVC project I have added a parameters.xml file that looks like:
I have the following compiled query added to my ASP.NET MVC 2 project (as
I have an asp.net MVC app that also has a silverlight project for some
I'm starting an ASP.NET MVC project using SubSonic 3 ActiveRecord. I added a table
I've added an App_Code directory to my ASP.NET MVC project so that I get
In our ASP.NET MVC project we have a Strings.resx file and the accompanying autogenerated

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.