Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using microsoft inbuilt authorization in asp.net mvc.
I am using below call in startup.auth.cs. I am getting prompt in mobile for authorization after allowing it is not redirecting in default page.
C#
private static string clientId = ConfigurationManager.AppSettings["ida:ClientId"];           
        public void ConfigureAuth(IAppBuilder app)
        {
            app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

            app.UseCookieAuthentication(new CookieAuthenticationOptions());

            app.UseOpenIdConnectAuthentication(
                new OpenIdConnectAuthenticationOptions
                {
                    ClientId = clientId,
                    Authority = authority,                    
                    PostLogoutRedirectUri = postLogoutRedirectUri
                });
        }


What I have tried:

I tried multiple ways but not getting correct one
Posted
Updated 30-Jun-23 7:08am
v2

1 solution

It seems like you're facing a problem with redirecting to the default page after successful authorization when using Microsoft's built-in authorization in an ASP.NET.

Try following steps for troubleshooting;

1. Verify Redirect URI: Ensure the redirect URI in your application matches exactly with what is configured in your identity provider.

2. Set RedirectUri Property: Explicitly set the RedirectUri in OpenIdConnectAuthenticationOptions to your application's redirect URI.
C#
RedirectUri = "http://localhost:port/signin-oidc"

3. Handle Authentication Failures:
Monitor the AuthenticationFailed event to catch and handle any authentication errors.
C#
Notifications = new OpenIdConnectAuthenticationNotifications
{
    AuthenticationFailed = context =>
    {
        context.Response.Redirect("/Home/Error");
        return Task.FromResult(0);
    }
};


4. Check Startup Class Configuration: Ensure your Startup class is correctly recognized by OWIN with the [assembly: OwinStartup(typeof(YourNamespace.Startup))] attribute.

5. Review Session and Cookie Settings: Make sure cookies are correctly configured to maintain sessions, especially for mobile browsers.

6. Implement Logging: Add logging throughout the authentication process to identify where the process might be failing.

7. Investigate Mobile-Specific Issues: Since the problem occurs on mobile, look for any mobile-specific settings or behaviors that might be affecting the authentication flow.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900