사용자 지정 인증 도메인 서비스를 쓰려고합니다. 필자는 this blog에 작성된 모든 코드를 이해했다고 생각합니다.사용자 지정 인증 도메인 서비스 - Silverlight 및 RIA
그러나 도메인 서비스 응용 프로그램을 사용해야하는 방법을 지정하는 방법을 모르겠습니다. 나는 하나의 추상 도메인 서비스를 가지고 있고 두 번째 것은이 서비스의 구체적인 구현이다. 전체 솔루션을 구축하면 오류가 발생합니다.
'MainModule.Web.FormsAuthenticationService`1' is not a valid DomainService type. DomainService types cannot be abstract or generic.
내가 전에 언급 한 블로그에서 소스 코드를 찾지 못했습니다.
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;
}
}
}
이것은 구현 된 클래스입니다. 블로그에 게시되는 코드와 동일합니다. 예외가 없으므로 stackTrace를 붙여 넣을 수 없습니다. 방금 솔루션을 컴파일 할 수 없습니다.
오류 메시지의 코드 및 전체 스택 추적을 봅니다. –
@ 라미. 내 질문을 편집했습니다. stacktrace를 붙여 넣을 수 없도록 솔루션을 빌드 할 수 없다는 사실을 알립니다. – John
컴파일러 오류를 가리키는 행은 무엇입니까? –