Registering a Sitefinity Custom Membership provider - membership-provider

I am trying to implement a custom membership provider in Sitefinity, and have followed through the documentation at: http://docs.sitefinity.com/tutorial-create-a-custom-membership-provider
When I come to register the provider in the Sitefinity backend, I get the message The following required properties are not set: type
I have checked, double checked and checked again the namespace and class names, and can even declare a variable as the provider type in the code-behind, yet it just won't have it.
My provider is defined thus:
namespace SitefinityWebApp
{
public class WebsiteMembersProvider : MembershipDataProvider
{
public WebsiteMembersProvider()
{
//... etc
I am registering the provider in the SF backend as:
SitefinityWebApp.WebsiteMembersProvider, SitefinityWebApp
And I can go into the code behind on one of my master pages and code:
SitefinityWebApp.WebsiteMembersProvider MyTestProvider;
and indeed, the class appears in the intellisense offerings just fine.
and the project all compiles/runs fine - but SF won't let me use the custom provider! I have also tried adding the provider manually in the securityconfig.config file - similar result.
Any idea anyone?

I went through the tutorial to try it myself and ran into the same problem as you.
Are you sure that you're putting this
SitefinityWebApp.WebsiteMembersProvider, SitefinityWebApp
in the ProviderType field (and not the 'Global resource class ID' field, which is what I initially did)? It seems like that error message shows up if I remove the text from that field and attempt to save (and also when it can't resolve that type).
Otherwise, I'm not sure what else it could be, aside from maybe recycling the app pool.

Related

ASP.NET Core 6 MVC : adding identity failing

I'm using VS 2022, ASP.NET Core 6 MVC and Microsoft SQL Server 2019 (v15).
Git project: [https://github.com/Wizmi24/MVC_BookStore]
I'm trying to add --> new scaffolded item --> identity.
Default layout page, override all files and mine Data context
when I click add, I get this error:
There was an error running the selected code generator:
'Package restore failed. Rolling back package changes for 'MyProjectName'
I cleared NuGet Package cache as I saw it may help, but all it do is just prolong and this same error is visible after trying to install Microsoft.EntityFrameworkCore.SqlServer, which is installed. I checked the packages and made sure they are the same version (6.0.11).
I cloned your project to test, and the problem you mentioned did appear. Not sure why, but I finally got it working by updating the NuGet package:
I updated the two packages Microsoft.EntityFrameworkCore and Microsoft.EntityFrameworkCore.Relational to version 7.0.1 (you need to pay attention to the sequence when updating), then add scaffolded Identity, and I succeeded.
You can try my method, if the Identity is successfully added, but the following exception is encountered at runtime:
You need to add builder.Services.AddDbContext<MyBookContext>(); before
builder.Services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<MyBookContext>();
MyBookContext is the Data context class selected when you add Identity:
In addition, if there is a 404 error in your area routing, you can refer to this document to modify it.
Hope this can help you.
Edit1:
I think it might be a problem caused by naming duplication. Please try to change the name of the context generated by Identity.
As you can see, the ApplicationDbContext generated by Identity is consistent with the ApplicationDbContext namespace in your MyBook.DataAccess:
So naming the same will cause conflict:
So you need to change the naming to avoid conflicts. For example:
builder.Services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(
builder.Configuration.GetConnectionString("DefaultConnection")
));
builder.Services.AddDbContext<ApplicationDbContextIdentity>();
builder.Services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContextIdentity>();
Edit2:
As I mentioned in the original answer, if you get a 404 error, you can try to refer to this link to fix the area routing.
The easiest way is to directly change the routing settings in Program.cs:
app.MapAreaControllerRoute(
name: "Customer",
areaName: "Customer",
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
Then add the Area property to the controller:
[Area("Customer")]
public class HomeController : Controller{}
There seems to be a problem with your Repository.cs, so I changed the Index to only output a string to test the result.
public string Index()
{
return "success";
}
Test Result:
If your Repository.cs also has problems when you test it, you can make a new post for everyone to help you fix this problem(Because this question strays so far from your original question, one post is better off addressing only one question).
Good Luck.

Error trying to scaffold a view in ASP.NET Core 6.0 MVC

I'm trying to scaffold a new razor view using Visual Studio. I select a template, my model and my DbContext, then I get the error message shown below.
Things to note. My models, my DbContext and my website are all in different projects. From the message below I am using AddDbContext and I have a constructor that accepts a DbContextOptions<TContext> parameter.
I read a comment on a blog post that the issue is because my context is in another project. The comment referenced something about the need to inject the Configuration into the DbContext to get the connection string and manually add it in the OnConfiguring override.
I can't find any examples if this is correct or how to set it up. Any help would be appreciated.
EDIT:
Testing out the theory from the blog comment I mentioned above, I added this section into my DbContext. ConnectionString is a hardcoded string constant with my connection information. This does work and allow me to scaffold, so the question still remains. How can I inject this connection string into my DbContext to allow the scaffolding to work?
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlServer(ConnectionString);
}
else
{
base.OnConfiguring(optionsBuilder);
}
}
EDIT: So after making this change, I checked in the code and had another developer pick it up. It appears this section above just needs to be there to allow scaffolding to work. He never changed the connection string to point to his environment. He no longer got the error above it just worked.
I am not sure about what is the actual problem but it seems like we were having problems creating DbContext at design time. I manually added the code below and it's working now. It's just a temporary solution tho.
public AppDbContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<AppDbContext>();
optionsBuilder.UseSqlServer("Data Source=.;Initial Catalog=JwtTemplate;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
return new AppDbContext(optionsBuilder.Options);
}
Reference: https://stackoverflow.com/a/70559350

Xamarin Prism Unable to navigate to LoginPageViewModel

I am trying to make my Xamarin Project use MVVM with Prism and DryIoc.
I mostly want to use AutoRegistration like below:
[AutoRegisterForNavigation]
...
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
//Pages
containerRegistry.RegisterForNavigation<NavigationPage>();
//Services
containerRegistry.RegisterSingleton<ILocalDatabase, LocalDatabase>();
containerRegistry.RegisterSingleton<IUserProfileDataStore, UserProfileDataStore>();
containerRegistry.RegisterSingleton<IApplicationSettings, ApplicationSettings>();
containerRegistry.RegisterSingleton<ILogger, Logger>();
containerRegistry.RegisterSingleton<IApiService, ApiService>();
containerRegistry.RegisterSingleton<IUserSession, UserSession>();
containerRegistry.Register<IBrowser, BrowserImplementation>();
containerRegistry.Register<IConnectivity, ConnectivityImplementation();
containerRegistry.Register<IFileSystem, FileSystemImplementation>();
containerRegistry.Register<ICoreServices, CoreServices>();
}
I have also tried Manual Registration:
containerRegistry.RegisterForNavigation<LoginPage, LoginPageViewModel>();
Neither works, It hits the Login Page code behind then breaks with the following error:
Exception - High: Prism.Ioc.ContainerResolutionException:
An unexpected error occurred while resolving 'AppetiteApp.ViewModels.LoginPageViewModel' --->
DryIoc.ContainerException: code: UnableToResolveUnknownService; message: Unable to resolve
Resolution root AppetiteApp.ViewModels.LoginPageViewModel
with passed arguments [value(Prism.Navigation.ErrorReportingNavigationService)]
**System.NullReferenceException:** 'Object reference not set to an instance of an object.'
I've also tried using a Linker file setting it's build action to "linkdescription"
As for my Login Page here is the declaration
public LoginPageViewModel(ICoreServices coreServices)
: base(coreServices)
The constructor of LoginPageViewModel requires the ICoreServices argument which is registered.
The error message says that the LoginPageViewModel itself is unknown to the IoC - it means the type LoginPageViewModel is not directly registered and not found through dynamic registrations or unknown service resolvers.
I am not a user of the Xamarin Prism so I am not sure about its mechanism for registering the view models.
Btw, this part of error
Resolution root AppetiteApp.ViewModels.LoginPageViewModel
with passed arguments [value(Prism.Navigation.ErrorReportingNavigationService)]
basically means the view-model was resolved via the foollowing call resolver.Resolve(typeof(LoginPageViewModel), args: new[] { errorReportingNavigationService })
Hope it will help you or someone knowledgeable in Xamarin to track the error cause.
So Once I investigated Inside of ICoreServices I commented out each of the dependencies then discovered that IUserSession was the once causing problems then I dug into that and discovered that the dependences for IAppInfo and IVersionTracking were missing in the App.Xaml.cs registr tyepes so I added that and then it worked!
containerRegistry.Register<IAppInfo, AppInfoImplementation>();
containerRegistry.Register<IVersionTracking, VersionTrackingImplementation>();

How to reference an initialized embedded RavenDB instance in a Class Library?

My scenario is this:
I have a custom RavenDB membership provider that is implemented in a class library (DLL). This provider needs to access a database to store and retrieve User and Role information. I'd like to use the same app database to store membership information to avoid having one more database.
I don't know how to get a reference to the already initialized database (app database) inside the class library code. I think I'm going the wrong way here... :)
Some code:
bool embeddedStore = Convert.ToBoolean(config["enableEmbeddableDocumentStore"]);
if (embeddedStore)
{
_documentStore = new EmbeddableDocumentStore()
{
// Here I'm using the same connection string used by the app.
// This gives me an error when I try to open a session in the DocumentStore.
ConnectionStringName =
config["connectionStringName"]
};
}
else
{
_documentStore = new DocumentStore()
{
ConnectionStringName =
config["connectionStringName"]
};
}
This is the connection string present in Web.config:
<add name="RavenDB" connectionString="DataDir = ~\App_Data\Database" />
How can I reuse the same database within the custom membership provider? Any ideas?
I thought about moving the class library code files to the Web project. This way I could get a reference to the DocumentStore easily, but the code wouldn't be as organized as I'd like.
I also tried to use 2 RavenDB databases: 1 for the app and 1 for the membership provider, but as I'm running RavenDB in its embeddable fashion I couldn't get it working.
These are the errors I got during my attempts so far:
RavenDB Could not open transactional storage.
Temp path already used by another database instance.
You need to pass the instance of the opened document store to your dll.
You can do that using a container or by providing an API call to do that.
You can't have two instance using the same db.

Monodroid emulator retrieving location problem

I am having difficulty getting my Monodroid application retrieve a location when I run it in an emulator. My code looks something like this:
LocationManager locationsManager = (LocationManager)threadSurfaceView.Context.GetSystemService(Context.LocationService);
location = locationsManager.GetLastKnownLocation(Android.Content.Context.LocationService);
However, this always seems to return null. Do I have to configure the emulator in some way so that it has a locaion service and/or location?
I also tried adding a LocationListener:
locationListener = new MyLocationListener();
locationsManager.RequestLocationUpdates(LocationManager.GpsProvider, 120000, 0, locationListener);
But the problem I had here was to create the MyLocationListener class. I implemented the four public methods (OnLocationChanged(Location) and so on), but Visual Studio complained about a missing Android.Runtime.IJavaObject method - does anyone have a simple example of a class that implements ILocationListener?
Thanks for any help. Martin
I got a kindly link to a sample at
https://github.com/gshackles/Sample-Projects/blob/master/MonoDroid/MonoDroidSamples/MonoDroidSamples/DemoActivities/LocationDemo/LocationActivity.cs
Which works fine on my Nexus S but still will not work on the emulator - so (perhaps) the issue is not a code issue.
I liked the technique in this sample of getting the "Activity" to implement ILocationListener as well as Activity - a neat solution to getting data back out of the "listener" function which had been giving me headaches when it was wrapped into another class.
I downloaded the bundle of samples and if you do the same then you will need to grab an mp3 file - rename it volbeat.mp3 and add it to the "raw" folder within "Resources" as it is missing.
partial answer as I am working on the same problem.
Your listener class that implements ILocationListener needs to be declared like
public class myLocationListener : Java.Lang.Object, ILOcationListener
{
//plus the public functions you identified
}
My attempt looks like this:
Android.Locations.Location iAmHere;
LocationManager myLoc = (LocationManager)GetSystemservice(Context.LocationService);
iAmHere = myLoc.GetLastKnownLocation(Android.Content.Context.LocationService);
but iAmHere is null on the emulator even when I have used TelNet to push a geo fix location through

Resources