Post Processing Hook to set Subscription Timeout?
My Ecommerce application is to provide access to Private Sitefinity Blog Content for a period of a year, just like a magazine subscription.
I have Ecommerce working to grant the user the correct Role Permissions after their purchase but I need a method of having their Role expire 365 days from the date of purchase.
Hello Rick,
You can use any .Net based Job Scheduler for doing this task. For this example I am using Quartz.net . You can add it to your project by using Nuget (http://nuget.org/packages/Quartz/1.0.3 )
Then add this below code to your application. Please feel free to change the code below according to your needs.
using
System;
using
System.Linq;
using
Quartz;
using
Telerik.Sitefinity.Security;
using
Telerik.Sitefinity.Abstractions;
namespace
SitefinityWebApp
public
class
HourlyJob : IJob
public
HourlyJob()
public
static
void
ScheduleJob(IScheduler sc)
JobDetail job =
new
JobDetail(
"HourlyJob"
,
"ExecuteTask"
,
typeof
(HourlyJob));
sc.ScheduleJob(job, TriggerUtils.MakeHourlyTrigger(
"HourlyTrigger"
));
sc.Start();
public
void
Execute(JobExecutionContext context)
try
Guid roleId = Guid.NewGuid();
//Id of the role you want to remove the user from.
RoleManager roleManager = RoleManager.GetManager();
UserManager userManager = UserManager.GetManager();
var role = roleManager.GetRole(roleId);
var users = userManager.GetUsers();
foreach
(var user
in
users)
if
(roleManager.IsUserInRole(user.Id, role.Id) && MyCustomRuleForDeterminingIfUserHasToBeRemovedFromRole(user.Id,role.Id))
roleManager.RemoveUserFromRole(user.Id, role);
catch
(Exception ex)
Log.Write(ex);
private
bool
MyCustomRuleForDeterminingIfUserHasToBeRemovedFromRole(Guid userId, Guid roleId)
//Add your custom logic here
return
true
;
protected
void
Application_Start(
object
sender, EventArgs e)
HourlyJob.ScheduleJob(
new
StdSchedulerFactory().GetScheduler());
Is this still the best method of implementation of a membership with time limit? I am now using SF version 10.0