I am needing to redirect a user to a specific page after they have logged in and I know what type of user they are based on custom profile settings we have. The hook for ILoginCompletedEvent is working fine. I get to the LoginCompletedEventVerification method when I would expect to. The custom profile part "PTL_Extensions.Security.IsClient(userIDGuid)" is working fine. The redirect is where I need some assistance.
I have found and followed the guidance given in the following two articles:
HOW TO REDIRECT TO SPECIFIC PAGE UPON LOGIN
https://knowledgebase.progress.com/articles/Article/How-to-redirect-to-specific-page-upon-login
and
ILoginCompletedEvent FOR DEVELOPERS
https://www.progress.com/documentation/sitefinity-cms/for-developers-ilogincompletedevent
My LoginCompletedEventVerification method is as follows:
private void LoginCompletedEventVerification(ILoginCompletedEvent evt)
{
if (evt.LoginResult == UserLoggingReason.Success)
{
var userName = evt.Username;
var userEmail = evt.Email;
var userIDGuid = Guid.Parse(evt.UserId);
var userIP = evt.IpAddress;
//if (!PTL_Extensions.Security.IsEmployee(currentUser.Id))
if (PTL_Extensions.Security.IsEmployee(userIDGuid))
{
// redirect to Legacy Premier iFrame page
Response.Redirect("/my-premier/my-premier-legacy");
}
else if (PTL_Extensions.Security.IsClient(userIDGuid))
{
// redirect to Client Dashboard
Response.Redirect("/my-premier/customer-dashboard");
}
else
{
//redirect to Home Page
}
}
}
If I uncomment the Response.Redirect("/my-premier/customer-dashboard"); lines, I get the following exception:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Response is not available in this context.
Source Error:
Line 104: {
Line 105: // redirect to Legacy Premier iFrame page
Line 106: Response.Redirect("/my-premier/my-premier-legacy");
Line 107: }
Line 108: else if (PTL_Extensions.Security.IsClient(userIDGuid))
|
Source File: C:\PTL\POC\PTL_POC\Global.asax.cs Line: 106
Stack Trace:
[HttpException (0x80004005): Response is not available in this context.] System.Web.HttpApplication.get_Response() +9983123 SitefinityWebApp.Global.LoginCompletedEventVerification(ILoginCompletedEvent evt) in C:\PTL\POC\PTL_POC\Global.asax.cs:106 [TargetInvocationException: Exception has been thrown by the target of an invocation.] System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0 System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +160 System.Delegate.DynamicInvokeImpl(Object[] args) +117 Telerik.Sitefinity.Services.Events.HandlerList.Invoke(IEvent event, Boolean throwExceptions) +186 [EventHandlerInvocationException: Response is not available in this context.] Telerik.Sitefinity.Owin.Extensions.<Invoke>d__1.MoveNext() +324 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58 Telerik.Sitefinity.Owin.<Invoke>d__1.MoveNext() +217 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.<RunApp>d__5.MoveNext() +182 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.<DoFinalWork>d__2.MoveNext() +180 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar) +69 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar) +65 System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +380 System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +48 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +159 |
I have now also tried implementing the code found in this article:
MVC: REDIRECT TO CUSTOM PAGE AFTER LOGIN
https://knowledgebase.progress.com/articles/Article/MVC-Redirect-to-custom-page-after-login
Once again, though the hook is triggered and the input.RedirectUrlAfterLogin is set, while the result this time is not an exception, it is NOT redirected to the desired page. Instead, I end up on my login page with the message "You are already logged in" displayed.
Any help or direction would be great. Thanks, Chris