1

I have one ASP .NET MVC application. It is having both MVC controllers and API controllers. I am using OAUTH 2 for authentication. When i enable OAUTH authentication, it shows authorization error for normal controller action also.

The code i am using for registering authentication.

app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
        var config = new HttpConfiguration();
        AppStart(config);
        SwaggerConfig.Register(config);
        HttpServer server = new HttpServer(config);
        // Accepts OAuth Service v1.0 tokens
        if (!string.IsNullOrEmpty(IdentifierUrl))
        {
            app.Map(
                new PathString("/v1"),
                p =>
                {
                    // Map to use OAuth 1 tokens            
                    p.UseEsoAccessTokenValidation(new EsoAccessTokenOptions { AuthorizationServerUrl = AuthorizationServer, Audiences = IdentifierUrl.Split(',') });
                    p.UseWebApi(server);
                });
        }

        // Accepts OAuth Service v2.0 tokens
        //app.Map("/v2", v2app =>
        //{
        app.UseEsoAccessTokenValidation(new EsoAccessTokenOptions
        {
            AuthorizationServerUrl = AuthorizationServer,
            Scopes = Scopes.Split(',')
        });

This is the error i am getting for each and every urls.

error page

1
  • Got any resolution? i getting this error on Web server for deployed site. Commented Aug 8, 2022 at 12:38

1 Answer 1

1

I suggest doing the following.

If you want authorization on:

[Authorize]
public class AdminController : Controller
{
  //Action methods here
}

If you want to disable it:

    [AllowAnonymous]
    public class AdminController : Controller
    {
      //Action methods here
    }

EDITED

So as you mention you're having issues accesing the root...

There are a few things you can try!

1. Change the portnumber

Project properties > Web

enter image description here

2. Delete .vs hidden folder

  1. Go to your project folder and open .vs folder (keep your check hidden item-box checked as this folder may be hidden sometimes)

  2. in the .vs folder - open config

  3. see that applicationhost config file there? Delete that thing.(Do not worry it will regenerate automatically once you recompile the project.)

3. Or try create a new virtual directory

Project properties > Web > Create Virtual Directory worked for me

Sign up to request clarification or add additional context in comments.

1 Comment

But from the root url itself i am getting this error. i mean localhost:4567

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.