- animationsamplecode.zip
- AnimationSampleCode
- AnimationSampleCode.sln
- AnimationSampleCode.suo
- AnimationSampleCode.Web
- AnimationSampleCode
- AnimationFirstExample.xaml
- AnimationFirstExample.xaml.cs
- AnimationSampleCode.csproj
- AnimationSampleCode.csproj.user
- AnimationWithCSharp.xaml
- AnimationWithCSharp.xaml.cs
- App.xaml
- App.xaml.cs
- Assets
- Bin
- Debug
- ActivityControl.dll
- AnimationSampleCode.dll
- AnimationSampleCode.xap
- AppManifest.xaml
- de
- System.ComponentModel.DataAnnotations.resources.dll
- System.Windows.Controls.Data.Input.resources.dll
- System.Windows.Controls.Navigation.resources.dll
- System.Windows.Controls.resources.dll
- System.Windows.Data.resources.dll
- es
- System.ComponentModel.DataAnnotations.resources.dll
- System.Windows.Controls.Data.Input.resources.dll
- System.Windows.Controls.Navigation.resources.dll
- System.Windows.Controls.resources.dll
- System.Windows.Data.resources.dll
- fr
- System.ComponentModel.DataAnnotations.resources.dll
- System.Windows.Controls.Data.Input.resources.dll
- System.Windows.Controls.Navigation.resources.dll
- System.Windows.Controls.resources.dll
- System.Windows.Data.resources.dll
- it
- System.ComponentModel.DataAnnotations.resources.dll
- System.Windows.Controls.Data.Input.resources.dll
- System.Windows.Controls.Navigation.resources.dll
- System.Windows.Controls.resources.dll
- System.Windows.Data.resources.dll
- ja
- System.ComponentModel.DataAnnotations.resources.dll
- System.Windows.Controls.Data.Input.resources.dll
- System.Windows.Controls.Navigation.resources.dll
- System.Windows.Controls.resources.dll
- System.Windows.Data.resources.dll
- ko
- System.ComponentModel.DataAnnotations.resources.dll
- System.Windows.Controls.Data.Input.resources.dll
- System.Windows.Controls.Navigation.resources.dll
- System.Windows.Controls.resources.dll
- System.Windows.Data.resources.dll
- System.ComponentModel.DataAnnotations.dll
- System.ComponentModel.DataAnnotations.xml
- System.Windows.Controls.Data.DataForm.Toolkit.dll
- System.Windows.Controls.Data.Input.dll
- System.Windows.Controls.Data.Input.xml
- System.Windows.Controls.dll
- System.Windows.Controls.Navigation.dll
- System.Windows.Controls.Navigation.xml
- System.Windows.Controls.xml
- System.Windows.Data.dll
- System.Windows.Data.xml
- System.Windows.Ria.dll
- System.Windows.Ria.xml
- TestPage.html
- zh-Hans
- System.ComponentModel.DataAnnotations.resources.dll
- System.Windows.Controls.Data.Input.resources.dll
- System.Windows.Controls.Navigation.resources.dll
- System.Windows.Controls.resources.dll
- System.Windows.Data.resources.dll
- zh-Hant
- System.ComponentModel.DataAnnotations.resources.dll
- System.Windows.Controls.Data.Input.resources.dll
- System.Windows.Controls.Navigation.resources.dll
- System.Windows.Controls.resources.dll
- System.Windows.Data.resources.dll
- Controls
- Generated_Code
- Helpers
- Libs
- ActivityControl.dll
- System.Windows.Controls.Data.DataForm.Toolkit.dll
- MainPage.xaml
- MainPage.xaml.cs
- Models
- Properties
- Views
- Web
- Resources
|
namespace AnimationSampleCode.Web
{
using System;
using System.Collections.Generic;
using System.Web.DomainServices;
using System.Web.Profile;
using System.Web.Ria;
using System.Web.Ria.Data;
using System.Web.Security;
using AnimationSampleCode.Web.Resources;
/// <summary>
/// RIA Services Domain Service that exposes methods for performing user
/// registrations.
/// </summary>
[EnableClientAccess]
public class UserRegistrationService : DomainService
{
// Users will be added to this role by default
public const string DefaultRole = "Registered Users";
//// NOTE: This is a sample code to get your application started. In the production code you would
//// want to provide a mitigation against a denial of service attack by providing CAPTCHA
//// control functionality or verifying user's email address.
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
public void AddUser(RegistrationData user)
{
// Run this BEFORE creating the user to make sure roles are enabled and the default role
// will be available
//
// If there are a problem with the role manager it is better to fail now than to have it
// happening after the user is created
if (!Roles.RoleExists(UserRegistrationService.DefaultRole))
{
Roles.CreateRole(UserRegistrationService.DefaultRole);
}
// NOTE: ASP.NET by default uses SQL Server Express to create the user database.
// CreateUser will fail if you do not have SQL Server Express installed.
MembershipCreateStatus createStatus;
Membership.CreateUser(user.UserName, user.Password, user.Email, user.Question, user.Answer, true, null, out createStatus);
if (createStatus != MembershipCreateStatus.Success)
{
throw new DomainException(ErrorCodeToString(createStatus));
}
// Assign it to the default role
// This *can* fail but only if role management is disabled
Roles.AddUserToRole(user.UserName, UserRegistrationService.DefaultRole);
// Set its friendly name (profile setting)
// This *can* fail but only if Web.config is configured incorrectly
ProfileBase profile = ProfileBase.Create(user.UserName, true);
profile.SetPropertyValue("FriendlyName", user.FriendlyName);
profile.Save();
}
// This is never used but without it RIA Services will complain RegistrationData
// is not exposed as an entity
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
public IEnumerable<RegistrationData> GetUsers()
{
throw new NotSupportedException();
}
private static string ErrorCodeToString(MembershipCreateStatus createStatus)
{
// See http://msdn.microsoft.com/en-us/library/system.web.security.membershipcreatestatus.aspx for
// a full list of status codes and add appropriate error handling.
switch (createStatus)
{
case MembershipCreateStatus.DuplicateUserName:
return ClientCultureBasedResources.GetResource(() => ErrorResources.MembershipCreateStatusDuplicateUserName);
case MembershipCreateStatus.DuplicateEmail:
return ClientCultureBasedResources.GetResource(() => ErrorResources.MembershipCreateStatusDuplicateEmail);
case MembershipCreateStatus.ProviderError:
return ClientCultureBasedResources.GetResource(() => ErrorResources.MembershipCreateStatusProviderError);
case MembershipCreateStatus.UserRejected:
return ClientCultureBasedResources.GetResource(() => ErrorResources.MembershipCreateStatusUserRejected);
case MembershipCreateStatus.InvalidPassword:
case MembershipCreateStatus.InvalidEmail:
case MembershipCreateStatus.InvalidAnswer:
case MembershipCreateStatus.InvalidQuestion:
case MembershipCreateStatus.InvalidUserName:
// All this errors should have been handled by the UI validation so theoretically
// we should never get to this point
return "Validation Error: " + createStatus.ToString();
default:
return "Could not register the user, please verify the provided information and try again.";
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.