Hi ,
I am creating a custom widget to redirect the pages to oauth login pages
code :
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Web; using System.Web.UI; using Telligent.Evolution.Extensibility.Api.Entities.Version1; using Telligent.Evolution.Extensibility.Api.Version1; using Telligent.Evolution.Extensibility.UI.Version1; using Telligent.Evolution.Extensibility.Version1; namespace Web.Community.Extensions.Plugins { public class Redirect : IPlugin, IHtmlHeaderExtension, IHttpCallback { public string Description { get { return "Redirects login, password and registration links"; } } public string Name { get { return " Redirect Plugin"; } } public void Initialize() { } public void ProcessRequest(System.Web.HttpContextBase httpContext) { } public string GetHeader(RenderTarget target) { object obj = (Object)null; if(HttpContext.Current.CurrentHandler is Page) obj = (Page)HttpContext.Current.CurrentHandler; if (HttpContext.Current.CurrentHandler is PageHandler) obj = (PageHandler)HttpContext.Current.CurrentHandler; // PageHandler page = HttpContext.Current.CurrentHandler as PageHandler; if (obj != null) { User accessingUser = TelligentPublicApi.Users.AccessingUser; if (TelligentPublicApi.Url.CurrentContext != null && accessingUser != null ) { //fix for language - set all users to en-US //run as the admin user TelligentPublicApi.Users.RunAsUser("admin", () => { if (accessingUser.Language != "en-US") { UsersUpdateOptions userOptions = new UsersUpdateOptions(); userOptions.Id = accessingUser.Id; userOptions.Language = "en-US"; List<ProfileField> profile = new List<ProfileField> { new ProfileField { Label = "Language", Value = "en-US" } }; userOptions.ProfileFields = profile; TelligentPublicApi.Users.Update(userOptions); } }); int accessingUserId = Convert.ToInt32(accessingUser.Id.ToString()); //check if this is the change password page switch (TelligentPublicApi.Url.CurrentContext.PageName) { case "user-changepassword": HttpContext.Current.Response.Redirect( Utilities.GetPluginConfigurationValue<Auth0Client>("_ChangePasswordUrl")); break; //check if this is the forgotten password page case "user-forgottenpassword": HttpContext.Current.Response.Redirect(Utilities.GetPluginConfigurationValue<Auth0Client>("_ForgottenPasswordUrl")); break; //check if this is the registration page case "user-createuser": HttpContext.Current.Response.Redirect(Utilities.GetPluginConfigurationValue<Auth0Client>("_RegistrationUrl")); break; case "user-consent": break; case "email-verification": if (Utilities.IsEmailVerified(accessingUserId) || !Utilities.IsLoggedIn(accessingUserId)) { HttpContext.Current.Response.Redirect($"{HttpContext.Current.Request.Url.Scheme}://{HttpContext.Current.Request.Url.Host}/"); } break; //check if this is the login page case "common-login": //check if the user is already logged in if (!Utilities.IsLoggedIn(accessingUserId)) { //get clean login url (no querystring) Telligent.Evolution.Extensibility.Api.Version1.CoreUrlLoginOptions loginOptions = new Telligent.Evolution.Extensibility.Api.Version1.CoreUrlLoginOptions(); loginOptions.ReturnToCurrentUrl = false; string loginUrl = TelligentPublicApi.CoreUrls.LogIn(loginOptions); string homeUrl = TelligentPublicApi.CoreUrls.Home(); //get any querystring paramaters string tokenKey = HttpContext.Current.Request.QueryString["oauth_data_token_key"]; string returnUrl = HttpContext.Current.Request.QueryString["ReturnUrl"]; string useOAuth = HttpContext.Current.Request.QueryString["UseOAuth"]; string errors = HttpContext.Current.Request.QueryString["Errors"]; //handle override to ignore oAuth redirect bool redirectToOAuth = true; if (!string.IsNullOrEmpty(useOAuth)) { if (useOAuth == "false") { redirectToOAuth = false; } } if (string.IsNullOrEmpty(tokenKey) && redirectToOAuth && string.IsNullOrEmpty(errors)) { //load oauth plugin to get auth url var OAuthPlugin = Telligent.Evolution.Extensibility.Version1.PluginManager.Get<Auth0Client>().FirstOrDefault(); if (OAuthPlugin != null) { HttpContext.Current.Response.Redirect(OAuthPlugin.GetAuthorizationLink()); } } } break; case "common-logout": // do nothing, do not remove break; default: if (Utilities.IsLoggedIn(accessingUserId) && !Utilities.IsEmailVerified(accessingUserId)) { var emailVerificationUrl = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Host + "/p/email-verification"; HttpContext.Current.Response.Redirect(emailVerificationUrl); } break; } } } return string.Empty; } public void SetController(IHttpCallbackController controller) { } public bool IsCacheable { get { return false; } } public bool VaryCacheByUser { get { return false; } } } }
The pages are redirected to specified in the configuration,
But its throwing a plugin initialization error when requesting these pages , login ,logout.
UnknownException: An error ocurred while rendering an HTML header extention. ---> System.Threading.ThreadAbortException: Thread was being aborted. at System.Threading.Thread.AbortInternal() at System.Threading.Thread.Abort(Object stateInfo) at System.Web.HttpResponse.AbortCurrentThread() at System.Web.HttpResponse.Redirect(String url, Boolean endResponse, Boolean permanent)
whats wrong with the code
Thanks