1. Use a template
[Enableclientaccess]
Public class authenticationdomainservice: authenticationbase <user>
{
}
Add
Public app ()
{
This. startup + = This. application_startup;
This. Exit + = This. application_exit;
This. unhandledexception + = This. application_unhandledexception;
Initializecomponent ();
VaR webcontext = new webcontext ();
VaR fa = new formsauthentication ();
Webcontext. Authentication = fa;
This. applicationlifetimeobjects. Add (webcontext );
}
2. Customize a verification class and add a CS File
[Enableclientaccess]
Public class authenticationdomainservice1: domainservice, iauthentication <authuser>
{
Public authuser getuser ()
{
Throw new notimplementedexception ();
}
Public authuser login (string username, string password, bool ispersistent, string customdata)
{
Throw new notimplementedexception ();
}
Public authuser logout ()
{
Throw new notimplementedexception ();
}
Public void updateuser (authuser user)
{
Throw new notimplementedexception ();
}
}
The problem is that the Custom User class cannot be used in two domainservices. For example, after <authuser> is changed to user, two identical attributes are generated on the client, an error occurs. Therefore, I added a class that inherits userbase.
In app. CS, specify the class to use for verification.
Public app ()
{
This. startup + = This. application_startup;
This. Exit + = This. application_exit;
This. unhandledexception + = This. application_unhandledexception;
Initializecomponent ();
VaR webcontext = new webcontext ();
VaR fa = new formsauthentication ();
Webcontext. Authentication = fa;
Fa. domaincontext = new authenticationdomainservice1 (); // specify the verification class
This. applicationlifetimeobjects. Add (webcontext );
}
The above two methods are used for verification. However, there is a problem, such as custom verification. The client obtains the current user's code in a somewhat different form from the default method.
Webcontext. Current. user;
Webcontext. Current. Authentication. user;
Sometimes there are some compatibility issues in the code, so you have to modify it. This is not very good. (It should be caused by the domainservice that implements the iauthentication interface on the server. Only one webcontext. Current. user can be seen. If there are two, no webcontext. Current. user can be seen.
It seems unstable.