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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:36:02+00:00 2026-05-27T15:36:02+00:00

I’m trying to write custom authentication domain service. I think I understood all code

  • 0

I’m trying to write custom authentication domain service. I think I understood all code which was written on this blog.

However I don’t know how to specify which domain service application should use. I have one abstract domain service and second one is a concrete implementation of this service. If I build entire solution I get an error

'MainModule.Web.FormsAuthenticationService`1' is not a valid DomainService type. DomainService types cannot be abstract or generic.

I didn’t find source code on blog which I mentioned before.

namespace MainModule.Web
{
    using System;
    using System.ServiceModel.DomainServices.Hosting;
    using System.ServiceModel.DomainServices.Server;



    // TODO: Create methods containing your application logic.
    [EnableClientAccess()]
    public abstract class FormsAuthenticationService<TUser> : DomainService, IAuthentication<TUser> where TUser : UserBase
    {

        protected abstract TUser GetCurrentUser(string name, string userData);
        protected abstract TUser ValidateCredentials(string name, string password, string customData, out string userData);
        protected virtual TUser GetDefaultUser()
        {
            return null;
        }

        public TUser GetUser()
        {
            IPrincipal currentUser = ServiceContext.User;
            if ((currentUser != null) && currentUser.Identity.IsAuthenticated)
            {
                FormsIdentity userIdentity = currentUser.Identity as FormsIdentity;
                if (userIdentity != null)
                {
                    FormsAuthenticationTicket ticket = userIdentity.Ticket;
                    if (ticket != null)
                    {
                        return GetCurrentUser(currentUser.Identity.Name, ticket.UserData);
                    }
                }
            }

            return GetDefaultUser();
        }

        public TUser Login(string userName, string password, bool isPersistent, string customData)
        {
            string userData;
            TUser user = ValidateCredentials(userName, password, customData, out userData);

            if (user != null)
            {
                FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(/* version */ 1, userName,
                                                           DateTime.Now, DateTime.Now.AddMinutes(30),
                                                           isPersistent,
                                                           userData,
                                                           FormsAuthentication.FormsCookiePath);

                string encryptedTicket = FormsAuthentication.Encrypt(ticket);
                HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);

                HttpContextBase httpContext = (HttpContextBase)ServiceContext.GetService(typeof(HttpContextBase));
                httpContext.Response.Cookies.Add(authCookie);
            }
            else
            {
                HttpContextBase httpContext = (HttpContextBase)ServiceContext.GetService(typeof(HttpContextBase));
                httpContext.AddError(new FormsAuthenticationLogonException("Username or password is not correct."));
            }

            return user;
        }

        public TUser Logout()
        {
            FormsAuthentication.SignOut();
            return GetDefaultUser();
        }

        public void UpdateUser(TUser user)
        {
            throw new NotImplementedException();
        }
    }
}

namespace MainModule.Web
    {
        using System.ServiceModel.DomainServices.Hosting;
        // TODO: Create methods containing your application logic.
        [EnableClientAccess()]
        public class CustomAuthenticationService :FormsAuthenticationService<UserDTO>
        {
            protected override UserDTO GetCurrentUser(string name, string userData)
            {
                return new UserDTO {DisplayName = name, Name = name};
            }

            protected override UserDTO ValidateCredentials(string name, string password, string customData, out string userData)
            {
                userData = null;
                UserDTO user = null;


               if(name=="John" && password = "123")
               {
                    userData = name;
                    user =  new UserDTO {DisplayName = name, Email = "asdf"};

                 }
              retrurn user;
            }
        }
    }

This are classes I implemeted – it’s the same code which is posted on blog. There is no exception so I can’t paste an stackTrace. I just can’t compile the solution

  • 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-27T15:36:03+00:00Added an answer on May 27, 2026 at 3:36 pm

    Make sure you are using the correct namespaces.

    I noticed two small typos in the code that you pasted:

    1. if(name=="John" && password = "123")
      Should be:
      if (name=="John" && password == "123")

    2. retrurn user;
      Should be:
      return user;

    Otherwise, it compiles without errors for me.

    1. Create a new Web Application

    2. Add a reference to System.ServiceModel.DomainServices.Hosting (ex. from “C:\Program Files (x86)\Microsoft SDKs\RIA Services\v1.0\Libraries\Server\System.ServiceModel.DomainServices.Hosting.dll”)

    3. Add a reference to System.ServiceModel.DomainServices.Server (ex. from “C:\Program Files (x86)\Microsoft SDKs\RIA Services\v1.0\Libraries\Server\System.ServiceModel.DomainServices.Server.dll”)

    4. Create a class called CustomAuthenticationService and insert the code below.

      using System.ServiceModel.DomainServices.Hosting;
      using System.Web;
      using System.Web.Security;
      using System;
      using System.Security.Principal;
      using System.ServiceModel.DomainServices.Server;
      using System.ServiceModel.DomainServices.Server.ApplicationServices;
      
      namespace WebApplication1.Services
      {
          public class UserDTO : UserBase
          {
              public string DisplayName { get; set; }
              public string Email { get; set; }
          }
      
          public class FormsAuthenticationLogonException : System.Exception
          {
              public FormsAuthenticationLogonException(string message) : base(message) { }
          }
      
          // TODO: Create methods containing your application logic.
          [EnableClientAccess()]
          public abstract class FormsAuthenticationService<TUser> : DomainService, IAuthentication<TUser> where TUser : UserBase
          {
      
              protected abstract TUser GetCurrentUser(string name, string userData);
              protected abstract TUser ValidateCredentials(string name, string password, string customData, out string userData);
              protected virtual TUser GetDefaultUser()
              {
                  return null;
              }
      
              public TUser GetUser()
              {
                  IPrincipal currentUser = ServiceContext.User;
                  if ((currentUser != null) && currentUser.Identity.IsAuthenticated)
                  {
                      FormsIdentity userIdentity = currentUser.Identity as FormsIdentity;
                      if (userIdentity != null)
                      {
                          FormsAuthenticationTicket ticket = userIdentity.Ticket;
                          if (ticket != null)
                          {
                              return GetCurrentUser(currentUser.Identity.Name, ticket.UserData);
                          }
                      }
                  }
      
                  return GetDefaultUser();
              }
      
              public TUser Login(string userName, string password, bool isPersistent, string customData)
              {
                  string userData;
                  TUser user = ValidateCredentials(userName, password, customData, out userData);
      
                  if (user != null)
                  {
                      FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(/* version */ 1, userName,
                                                             DateTime.Now, DateTime.Now.AddMinutes(30),
                                                             isPersistent,
                                                             userData,
                                                             FormsAuthentication.FormsCookiePath);
      
                      string encryptedTicket = FormsAuthentication.Encrypt(ticket);
                      HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
      
                      HttpContextBase httpContext = (HttpContextBase)ServiceContext.GetService(typeof(HttpContextBase));
                      httpContext.Response.Cookies.Add(authCookie);
                  }
                  else
                  {
                      HttpContextBase httpContext = (HttpContextBase)ServiceContext.GetService(typeof(HttpContextBase));
                      httpContext.AddError(new FormsAuthenticationLogonException("Username or password is not correct."));
                  }
      
                  return user;
              }
      
              public TUser Logout()
              {
                  FormsAuthentication.SignOut();
                  return GetDefaultUser();
              }
      
              public void UpdateUser(TUser user)
              {
                  throw new NotImplementedException();
              }
          }
      
          // TODO: Create methods containing your application logic.
          [EnableClientAccess()]
          public class CustomAuthenticationService : FormsAuthenticationService<UserDTO>
          {
              protected override UserDTO GetCurrentUser(string name, string userData)
              {
                  return new UserDTO { DisplayName = name, Name = name };
              }
      
              protected override UserDTO ValidateCredentials(string name, string password, string customData, out string userData)
              {
                  userData = null;
                  UserDTO user = null;
      
      
                  if (name == "John" && password == "123")
                  {
                      userData = name;
                      user = new UserDTO { DisplayName = name, Email = "asdf" };
      
                  }
      
                  return user;
              }
          }
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,

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.