Posted on 04/09/2019 10:21:26
Here is some more code:
public class AuthenticationHttpHandler : IHttpHandler, IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
context.Response.Clear();
// dynamicweb 9 requires page view to access LoginHandler
// check if has page view
new PageView().Load();
// determine api key based on endpoint
var partnerName = context.Request.QueryString["partner"];
var resolver = new AuthenticationHandlerResolver();
var handler = resolver.Get(context, partnerName);
var response = handler.Resolve(context);
if (response.Code == (int) ResponseCode.REDIRECT && handler.Type == HandlerType.OCI)
{
context.Response.Redirect(response.Message);
} else if (response.Code != (int)ResponseCode.OK)
{
context.Response.TrySkipIisCustomErrors = true;
}
context.Response.ContentType = response.ContentType;
context.Response.StatusCode = response.Code;
context.Response.Write(response.Message);
}
public bool IsReusable
{
get
{
return false;
}
}
}
In handler.Resolve(context); we do:
var tokenCreated = tokenService.Create(token);
// return xml response
if (tokenCreated)
{
var loginUrl = this.GetLoginUrl(tokenGuid);
response = GenericResponse.Redirect(loginUrl);
}
Which redirects to here:
public class LoginHttpHandler : IHttpHandler, IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
context.Response.Clear();
// dynamicweb 9 requires page view to access LoginHandler
// check if has page view
new PageView().Load();
var resolver = new LoginHandlerResolver();
var handler = resolver.Get(context);
var response = handler.Resolve(context);
if (response.Code == (int)ResponseCode.REDIRECT)
{
context.Response.RedirectLocation = response.Message;
}
else if (response.Code != (int)ResponseCode.OK)
{
context.Response.TrySkipIisCustomErrors = true;
}
context.Response.ContentType = response.ContentType;
context.Response.StatusCode = response.Code;
context.Response.Write(response.Message);
}
public bool IsReusable
{
get
{
return false;
}
}
}
In handler.Resolve(context); Login is called (which is where the exception occurs):
public static bool Login(string username, string password)
{
try
{
Dynamicweb.Security _sec = new Dynamicweb.Security();
_sec.ExtranetLogin(username, password, true);
return _sec.UserLoggedIn;
}
catch (Exception e)
{
throw e;
}
}
I understand you can set redirects on the user from the /Admin entrance of DynamicWeb but that is not the redirects you are referring to here, right? From what I understand from what you write, the exception occurs because Dynamicweb detects a redirect from Auth to Login before the login attempt. Correct?
How do I solve this and still have that redirect from Auth to Login?
We got this working on a different solution.