skip to Main Content

I have 2 projects that need to share authentication and I’m using Owin cookies.
The first project is an asp.net webform application <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>

when the user logs in I need to store it in the cookie.

User u = User.GetUser(username,password); //this is my object
 var identity = new System.Security.Claims.ClaimsIdentity(
           new List<System.Security.Claims.Claim>
           {
                new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.NameIdentifier, u.IdUtente.ToString()),
                new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.Name, u.utente)
           },
           CookieAuthenticationDefaults.AuthenticationType,
           System.Security.Claims.ClaimTypes.Email,
           System.Security.Claims.ClaimTypes.Role
           );

            var principal = new System.Security.Claims.ClaimsPrincipal(identity);

            var ctx = Request.GetOwinContext(); //HERE I'm GETTING THE ERROR
            ctx.Authentication.SignIn(identity);

The code line Request.GetOwinContext(); gives me the following error

'HttpRequest' does not contain a definition for GetOwinContext and no accessible extension method GetOwinContext accepting a first argument of type HttpRequest

I found on the internet that I have to install the NuGet Microsoft.Owin.Host.SystemWeb
enter image description here
If I install this nuget and the problem disappears but when I start my application I’m getting the error:

Cannot load file or assembly 'Mono.Android, Version = 0.0.0.0, Culture = neutral, PublicKeyToken = 84e04ff9cfb79065' or one of its dependencies. Cannot find the specified file.

enter image description here

I can’t understand the motivation.
Any help?

2

Answers


  1. Chosen as BEST ANSWER

    I fixed downloading the dll from the web and adding the reference manually. But the error it's still not clear.


  2. This issue can happen on any project that uses NuGet packages. If after updating or installing NuGet packages in your project or solution,
    you see an error that is mentioning some missing references or dependencies it means that either something is broken inside
    or package is not installed correctly because of many uncertain reasons.
    I have also faced similar issues so let me try to list down few solutions which resolved my issues.

    1. Go to package manager console and run following command:-
      Update-Package -reinstall`

      This will initiate reinstallation of each nuget package within that project which should resolve any missing references.
      If you came to know that you’re missing a specific reference:

      Update-Package -reinstall

      Restart visual studio
      This will resolve the issue which are related to VS or its caching.

    2. You may need to check the version of the package vs. your project.

    3. Sometimes you may need to clear the nuget cache. Nuget cache location can be found from nuget settings > general > browse.
      In few cases I just delete 1 single file from cache and then reinstall the package.

    4. Delete all the references from your .config file.

    Since you have solved the issue by adding dll but sometimes adding dll can give you issues in future if you are updating versions of dependent packages.

    Please try these and do let me know if you are still having the issue. Thanks

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