skip to Main Content

I am using ITFoxTec SAML 2.0 library.

From their sample code, I have this controller:

[AllowAnonymous]
[Route("Auth")]
public class AuthController : Controller
{
    const string relayStateReturnUrl = "ReturnUrl";
    private readonly Saml2Configuration config;

    public AuthController(IOptions<Saml2Configuration> options)
    {
        this.config = options.Value;
    }

    [Route("Login")]
    public IActionResult Login(LoginModel loginModel, string returnUrl = null)
    {

The problem is, I have no idea how it’s getting called. It gets called right when I start the app and all my other controllers are bypassed. Which is not the behavior I want.

I tried in vain stepping through the code line-by-line in visual studio, but there is nothing in my code that is calling this controller.

Is there anyway to trace how it’s getting called?

Thanks!

2

Answers


  1. The login sequence is started and call the login method, if you generally require the user to be authenticated or you decorate your controllers with [Authorize] attribute like in the sample.

    Otherwise, the login method should not be called automatically.

    Login or Signup to reply.
  2. I tried in vain stepping through the code line-by-line in visual
    studio, but there is nothing in my code that is calling this
    controller.

    Is there anyway to trace how it’s getting called?

    Well, since you are using ITFoxTec SAML 2.0 library, there should be a service in configuration wihtin program.cs file which calling SAML authentication flow that might be triggering the Login method. This could be due to SAML configuration settings or middleware that automatically initiates the SAML login process.

    Apart from this, using couple ways you could check hows the request sequence are being called behind the http rquest. You could use custom middleware, application logger like serilog or even can use .Net default logger.

    One of the way you could try writting a middleware which should be trace all the incoming and outgoing request and response. You could try as following:

    app.Use(async (context, next) =>
        {
            Console.WriteLine($"Request: {context.Request.Method} {context.Request.Path}");
            //logger.LogInformation($"Request: {context.Request.Method} {context.Request.Path}");
            await next.Invoke();
            //logger.LogInformation($"Response: {context.Response.StatusCode}");
            Console.WriteLine($"Response: {context.Response.StatusCode}");
            //If controller and action name also required
            var routeData = context.GetRouteData();
            if (routeData != null)
            {
                var controller = routeData.Values["controller"];
                var action = routeData.Values["action"];
               // logger.LogInformation($"Controller: {controller}, Action: {action}");
                Console.WriteLine($"Controller: {controller}, Action: {action}");
            }
       });
    

    Note: You either can directly check in Console or even can log them using logger.LogInformation either should provide you the request calling sequence.

    In addition, Application log or IIS log can also be very helpful if you want to check your application request trace.

    Output:

    enter image description here

    enter image description here

    enter image description here

    enter image description here

    Note: If you would like to keep track all the activity within your application, you could check this thread for getting more insight.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search