Im trying to add roles functionality to my app but I'm getting an error message that I don't really understand or know how to fix it.
Im trying to add The IdentityRole to services.AddIdentityCore but getting an error message:
"'IServiceCollection' does not contain a definition for 'AddIdentityCore' and no accessible extension method 'AddIdentityCore' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?) [API]csharp(CS1061)
Does anyone know how to implement it right?
What causes this issue ?
Thanks so much for the help
The solution is simple. Try this code like below:-
Your AppUser.cs model:-
public class AppUser:IdentityUser
{
...
}
Your startup.cs file:-
services.AddIdentity<AppUser, IdentityRole>(options=> {
options.Password.RequireDigit = false;
...
})
.AddEntityFrameworkStores<DataContext>()
.AddDefaultTokenProviders();
Try exact same code as above.It will resolve your issue.
Related
I have this C# code which use Entity Framework Core 5 which works
using (var context = new MyContext(_options))
{
context.ChangeTracker.Clear();
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
context.FileLogs.AddRange(fileLogs);
await context.SaveChangesAsync();
}
But after I downgrade it to Entity Framework Core 3.1.9, context.ChangeTracker.Clear() has syntax error. The error message is:
'ChangeTracker' does not contain a definition for 'Clear' and no
accessible extension method 'Clear' accepting a first argument of type
'ChangeTracker' could be found (are you missing a using directive or
an assembly reference?)
What is the solution to do the same for Entity Framework Core 3?
I am trying to setup my own Service Collection like so:
public static void AddMyServices(this IServiceCollection services)
{
services.AddServerSideBlazor();
//services.AddTransient<IMyService, MyService>();
}
I can't figure out how to get this running, I tried adding several NuGet References but none does work. e.g. Microsoft.AspNetCore.Components.Web to get AddServerSideBlazor(); working.
I want to use it like this in my Startup.cs:
public void ConfigureServices(IServiceCollection services)
{
services.AddMyServices();
}
The Error I get:
'IServiceCollection' does not contain a definition for
'AddServerSideBlazor' and no accessible extension method
'AddServerSideBlazor' accepting a first argument of type
'IServiceCollection' could be found (are you missing a using directive
or an assembly reference?)
Edit:
After some more looking into it I think the correct package is
Microsoft.AspNetCore.App.Ref but adding it via NuGet gives me this error:
The package Microsoft.AspNetCore.App.Ref 5.0.0 has a package type
DotnetPlatform that is incompatible with this project.
You will need to Extend the IServiceCollection.
public static Microsoft.Extensions.DependencyInjection.IServerSideBlazorBuilder AddServerSideBlazor (this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Action<Microsoft.AspNetCore.Components.Server.CircuitOptions>? configure = default);
found https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.dependencyinjection.componentservicecollectionextensions.addserversideblazor?view=aspnetcore-5.0
Newbie here, I am experiencing the following error and I have no idea how to resolve the issue. I did change the primary key for users in Identity to int rather than it being stored as a string.(I believe that is what's causing the issue). Besides that, every other page runs perfectly. Any ideas on where to start?
CS1503 Argument 1: cannot convert from 'System.Collections.Generic.ICollection<DraftIntellectualProperty.Models.CustomUserRole>' to 'System.Collections.Generic.ICollection<Microsoft.AspNet.Identity.EntityFramework.IdentityUserRole>'
The error:
The method being called in the code-behind:
Snip from IdentityModel:
Snip from IdentityUserRole class:
I am following the "RESTful WCF Service" tutorial. But when I built my application I get this error:
The type or namespace name 'ApplicationUser' could not be found (are you missing a using directive or an assembly reference?)
c:\users\basma\documents\visual studio 2013\Projects\OnlineStore2\OnlineStore2_Client\App_Start\IdentityConfig.cs
I've searched and many answers where talking about "Microsoft ASP.NET Identity.owin" but I added this reference but still get this error
Create a class called ApplicationUser that derives from IdentityUser. It doesn't need to have any properties or methods, but you can freely extend it with any information you want to store about each user you have on the system (think name, addresses, etc.).
public class ApplicationUser : IdentityUser
{
public virtual string Email { get; set; } // example, not necessary
}
Linking the namespace
using YourProjectName.Models;
worked for me. In the post's case, "YourProjectName" is "OnlineStore2"
I am trying to use Mike Wallace's "RequireHttps" attribute to force certain controllers to require SSL or not.
I have the code below, and it builds fine. But when I actually go to add the attribute to the controller, it fails.
I have other custom attributes that appear, and I have another that doesn't. So it might be a project issue, though I tried a new project and it still failed. The code is in the app_code folder.
using System;
using System.Net.Http;
using System.Web.Http.Filters;
using System.Web.Http.Controllers;
namespace WebAPIService
{
public class RequireHttpsAttribute : AuthorizationFilterAttribute
{
public RequireHttpsAttribute();
public override void OnAuthorization(HttpActionContext actionContext)
{
if (actionContext.Request.RequestUri.Scheme != Uri.UriSchemeHttps)
{
actionContext.Response = new HttpResponseMessage(System.Net.HttpStatusCode.Forbidden)
{
ReasonPhrase = "HTTPS Required"
};
}
else
{
base.OnAuthorization(actionContext);
}
}
}
}
Any suggestions are welcomed. Thanks.
EDIT:
The error I get on the API Controller is:
The type or namespace name 'RequireHttpsAttribute' could not be found (are you missing a using directive or an assembly reference?)
You can just put your RequireHttpsAttribute.cs file in a different folder than App_Code, which is a special ASP.NET folder. Your namespace import should function correctly, then. If your project is a website project, converting it to a web app might also solve the problem.
If you want to learn more about the issue, I recommend you take a look at Type or namespace could not be found from App_code folder.