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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:51:42+00:00 2026-06-14T08:51:42+00:00

We override the basic authentication in an MVC3 application by calling a webservice with

  • 0

We override the basic authentication in an MVC3 application by calling a webservice with the user’s credentials and returning a WCF structure that contains the user’s ID, a “LogonTicket”. This LogonTicket is used to “authenticate the user for each call made to the webservice.

Now, we override by replacing the defaultProvider in the Web.config. All we do in this overridden provider is
to override the ValidateUser() function. That is where we call the web service with their credentials and return
the “LogonTicket”.

This is the LogOn() function from our AccountController, essentially the base code from the template:

public ActionResult LogOn(LogOnModel model)
{
    string ReturnUrl = "";
    if (HttpContext.Request.UrlReferrer.Query.Length > 11)
    {
        ReturnUrl = Uri.UnescapeDataString(HttpContext.Request.UrlReferrer.Query.Substring(11));
    }
    if (ModelState.IsValid)
    {
        if (Membership.ValidateUser(model.UserName, model.Password))
        {
            FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
            if (Url.IsLocalUrl(ReturnUrl) && ReturnUrl.Length > 1 && ReturnUrl.StartsWith("/")
                && !ReturnUrl.StartsWith("//") && !ReturnUrl.StartsWith("/\\"))
            {
                return Redirect(ReturnUrl);
            }
            else
            {
                return RedirectToAction("Index", "Home");
            }
        }
        else
        {
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
        }
    }

    // If we got this far, something failed, redisplay form
    ViewBag.MainWebsite = MainWebsite;
    return View(model);
}

This is the overridden ValidateUser() function from our new default provider:

public override bool ValidateUser(string username, string password)
{
    MyServiceClient mps = new MyServiceClient();
    string sha1password = HashCode(password);
    LogonInfo logonInfo = mps.GetLogonTicket(username, sha1password);
    if (logonInfo.LogonTicket != "" && logonInfo.LogonTicket != "0") 
    {
    // Authenticated so set session variables
        HttpContext.Current.Session["LogonTicket"] = logonInfo.LogonTicket;
        HttpContext.Current.Session["ParticipantID"] = logonInfo.ParticipantID;
        return true;
    }
    else
    {
        return false;
    }
}

I’m not really sure how to combine the use of the two, so my questions are:

  1. How can I implement OpenID and Facebook logins and keep my current authentication method?
  2. How can we “map” the OpenID user with our current user DB values? We MUST know so we can retrieve their info.
    I know we can retrieve their email address but what if their OpenID email is different than the one they use for their record on our site?
  3. Are there any examples of how to do this, anywhere?

Thanks for looking at my question.

  • 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-14T08:51:44+00:00Added an answer on June 14, 2026 at 8:51 am

    I have done a project which required multiple log-on possibilities (custom account, Google and Facebook)

    In the end your authentication with ASP.NET is entirely dependant on your configuration. (In your case it is FormsAuthentication) this means that FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); basicly determines everything in regard to your user and where you set this isn’t restricted.

    You have now basicly the same implementation as we started out with, using a MembershipProvider to handle your own custom account. You only need to expand now to facilitate the openIds. You would have to expand your Controller with various actions for each login type (Now you have ActionResult LogOn() you can add to that for example: ActionResult LogOnOpenId()). Inside that method you basicly call the same code but instead of Membership.ValidateUser(model.UserName, model.Password) you call the OpenId services.

    I have provided below an example of our google implementation using dotnetopenauth. The service method uses formsService.SignIn(userId.Value.ToString(), false); which basicly calls FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); (we only do some custom behaviour there in regard to the SecurityPrincipal but this doesn’t affect your Authentication process). You can also see that we make a new account when we receive a new user. To solve your question part 2 we have implemented a profile which can be merged if you can provide another login. This allows our users to keep their account consolidated and use whatever login method they like.

    For examples in regard to multiple signons I will refer to the answer of Tomas whom referenced StackExchange as a good example. Also I’d advise you to install MVC4 and VS2012 and just do a File > New Project. The newest default template of MVC includes openid implementation alongside a custom login!

    Example google openid implementation:

    The controller method:

        public virtual ActionResult LoginGoogle(string returnUrl, string runAction)
        {
            using (var openId = new OpenIdRelyingParty())
            {
                IAuthenticationResponse response = openId.GetResponse();
    
                // If we have no response, start 
                if (response == null)
                {
                    // Create a request and redirect the user 
                    IAuthenticationRequest req = openId.CreateRequest(WellKnownProviders.Google);
                    var fetch = new FetchRequest();
                    fetch.Attributes.AddRequired(WellKnownAttributes.Name.First);
                    fetch.Attributes.AddRequired(WellKnownAttributes.Name.Last);
                    fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
                    fetch.Attributes.AddRequired(WellKnownAttributes.Preferences.Language);
                    req.AddExtension(fetch);
    
                    req.RedirectToProvider();
    
                    return null;
                }
    
                _service.ConnectViaGoogle(response, TempData);
        }
    

    The service method:

        public void ConnectViaGoogle(IAuthenticationResponse response, TempDataDictionary tempData)
        {
            // We got a response - check it's valid and that it's me 
            if (response.Status == AuthenticationStatus.Authenticated)
            {
                var claim = response.GetExtension<FetchResponse>();
                Identifier googleUserId = response.ClaimedIdentifier;
                string email = string.Empty;
                string firstName = string.Empty;
                string lastName = string.Empty;
                string language = string.Empty;
    
                if (claim != null)
                {
                    email = claim.GetAttributeValue(WellKnownAttributes.Contact.Email);
                    firstName = claim.GetAttributeValue(WellKnownAttributes.Name.First);
                    lastName = claim.GetAttributeValue(WellKnownAttributes.Name.Last);
                    language = claim.GetAttributeValue(WellKnownAttributes.Preferences.Language);
                }
    
                //Search User with google UserId
                int? userId = _userBL.GetUserIdByGoogleSingleSignOnId(googleUserId);
    
                //if not exists -> Create
                if (!userId.HasValue)
                {
                    _userBL.CreateGoogleUser(
                        googleUserId,
                        firstName,
                        lastName,
                        email,
                        language,
                        DBConstants.UserStatus.DefaultStatusId,
                        out userId);
                }
    
                if (userId.HasValue)
                {
                    _userBL.UpdateLastLogon(userId.Value);
                    var formsService = new FormsAuthenticationService();
                    formsService.SignIn(userId.Value.ToString(), false);
                    AfterLoginActions(tempData);
                }
            }
        }
    

    Any questions or comments? I’ll gladly hear them.

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

Sidebar

Related Questions

The basic question is: How do I perform a basic override of a plugin
I have a basic Cocoa app with a custom NSCollectionView that overrides drawRect: to
I've created a WCF DataService and for this service I require some custom authentication
I've created a custom Weblogic Security Authentication Provider on version 10.3 that includes a
This is a pretty basic question. Since browsers have a culture setting that the
I want to implement HTTP Basic Authentication for my web services, but I also
I'm trying to add simple Authentication and Authorization to an ASP.NET MVC application. I'm
I am a fairly beginner in Android Development. I am developing an application that
I understand basic AXML usage such as: protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle);
I refactored an attribute, which implements Basic Http Authentication in the Web api, to

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.