How to handle WCF Ria Forms authentication

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.