title: Change redirectURI and CallbackPath for AzureAD authentication in .net core 3.1.1 web app
body: <p>I created a new .net core 3.1.1 web application with the Razor Pages framework.
  When creating the app I set up the default Authentication as AzureAd.
  When I run the application the authentication works just fine.
  The generated appsettings file looks like this:</p>
  
  <pre><code>{
    "AzureAd": {
      "Instance": "https://login.microsoftonline.com/",
      "Domain": "myDomain",
      "TenantId": "myTenantId",
      "ClientId": "myClientId",
      "CallbackPath": "/signin-oidc"
    },
    "Logging": {
      "LogLevel": {
        "Default": "Information",
        "Microsoft": "Warning",
        "Microsoft.Hosting.Lifetime": "Information"
      }
    },
    "AllowedHosts": "*"
  }
  </code></pre>
  
  <p>I created a new controller in my app which looks very simple, just like:</p>
  
  <pre><code>namespace WebApplication1.Controllers
  {
      public class AccountController : Controller
      {
          [HttpGet]
          public void SignIn()
          {
             //here comes the logic which checks in what role is the logged User
             //the role management stuff will be implemented in the app
          }
      }
  }
  </code></pre>
  
  <p>This is how my Startup.cs looks like:</p>
  
  <pre><code>public class Startup
  {
      public Startup(IConfiguration configuration)
      {
          Configuration = configuration;
      }
  
      public IConfiguration Configuration { get; }
  
      // This method gets called by the runtime. Use this method to add services to the container.
      public void ConfigureServices(IServiceCollection services)
      {
          services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
              .AddAzureAD(options =&gt; Configuration.Bind("AzureAd", options));
          services.AddMvc(options =&gt;
          {
              options.EnableEndpointRouting = false;
          });
          services.AddRazorPages().AddMvcOptions(options =&gt;{});
      }
  
      // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
      public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
      {
          if (env.IsDevelopment())
          {
              app.UseDeveloperExceptionPage();
          }
          else
          {
              app.UseExceptionHandler("/Error");
              // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
              app.UseHsts();
          }
  
          app.UseHttpsRedirection();
          app.UseStaticFiles();
  
          app.UseRouting();
  
          app.UseAuthentication();
          app.UseAuthorization();
  
          app.UseEndpoints(endpoints =&gt;
          {
              endpoints.MapRazorPages();
              endpoints.MapControllers();
          });
  
          app.UseMvc(routes =&gt;
         {
              routes.MapRoute(
              name: "default",
              template: "{controller=Account}/{action=SignIn}");
         });
      }
  }
  </code></pre>
  
  <p>I'd would like to be able to change the AzureAd/CallbackPath to something different than "/signin-oidc" eg. I would like to change it to Account/SignIn. Then I'd like to catch the callback call from azure and based on the logged user email address I'd like to modify the token to add some system roles and make a redirect to the appropriate dashboard page based on the user role. There can be a different dashboard for admin and a client.</p>
  
  <p>So I tried to change the <code>"CallbackPath": "/Account/SignIn"</code> and I also updated RedirectURI in Azure:
  <a href="https://i.stack.imgur.com/aABBM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aABBM.png" alt="RedirectURI in Azure"></a></p>
  
  <p>Then I run the app once again, set a breakpoint in <code>void SignIn()</code>, I signed in once again, and instead of hitting the <code>/Account/SignIn</code> I was just redirected to the main page, <code>the https://localhost:44321</code>.
  I also tried to manually run the <code>https://localhost:44321/Account/SignIn</code> in the browser and I saw the following error message:</p>
  
  <pre><code>An unhandled exception occurred while processing the request.
  Exception: OpenIdConnectAuthenticationHandler: message.State is null or empty.
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/WFrOH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WFrOH.png" alt="enter image description here"></a></p>
  
  <p>I tried to check if there is something in the <a href="https://docs.microsoft.com/en-gb/azure/active-directory/develop/quickstart-configure-app-access-web-apis#add-redirect-uris-to-your-application" rel="nofollow noreferrer">documentation</a> but I didn't find anything useful.
  Any ideas about what should I do to make it work?
  Cheers</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I also use <code>Microsoft.AspNetCore.Authentication.AzureAD.UI</code> framework.</p>