Ответ 1
Если вы создаете "Бизнес-приложение Silverlight", вы увидите, как шаблон реализует аутентификацию. (Или просто перейдите здесь и загрузите образец образца шаблона.)
Для упрощения здесь используется следующий процесс:
Сначала я создаю службу домена (FooService), которая происходит из LinqToEntitiesDomainService, где FooContext является моей моделью сущности. В нем я добавляю все операции CRUD для доступа к моей пользовательской таблице DB и возвращению профилей пользователей.
Затем создайте конкретный класс User на сервере, выведя из UserBase:
using System.Web.Ria;
using System.Web.Ria.ApplicationServices;
public class User : UserBase
{}
Наконец, выведите класс из AuthenticationBase и выполните следующие четыре метода:
[EnableClientAccess]
public class AuthenticationService : AuthenticationBase<User>
{
private FooService _service = new FooService();
protected override bool ValidateUser(string username, string password)
{
// Code here that tests only if the password is valid for the given
// username using your custom DB calls via the domain service you
// implemented above
}
protected override User GetAuthenticatedUser(IPrincipal pricipal)
{
// principal.Identity.Name will be the username for the user
// you're trying to authenticate. Here one way to implement
// this:
User user = null;
if (this._service.DoesUserExist(principal.Identity.Name)) // DoesUserExist() is a call
// added in my domain service
{
// UserProfile is an entity in my DB
UserProfile profile = this._service.GetUserProfile(principal.Identity.Name);
user.Name = profile.UserName;
user.AuthenticationType = principal.Identity.AuthenticationType;
}
return user;
}
public override void Initialize(DomainServiceContext context)
{
this._service.Initialize(context);
base.Initialize(context);
}
protected override void Dispose(bool disposing)
{
if (disposing)
this._service.Dispose();
base.Dispose(disposing);
}
}