Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable registration template in ASP NET core

How can I disable the registration form in ASP NET Core 2.2.0+?

Just to get and remove the appropriate model, I can not, because it is not in the project, according to the documentation, I understand that this is connected with something like "ConfigureApplicationPartManager"

Link here

but I can not find an appropriate example to disable it

the goal is to disable the registration of new users, leaving only the Login \ Password form

services.AddMvc()
            .ConfigureApplicationPartManager(x =>
            {


                var thisAssembly = typeof(IdentityBuilderUIExtensions).Assembly;
                var relatedAssemblies = RelatedAssemblyAttribute.GetRelatedAssemblies(thisAssembly, throwOnError: true);
                var relatedParts = relatedAssemblies.ToDictionary(
                    ra => ra,
                    CompiledRazorAssemblyApplicationPartFactory.GetDefaultApplicationParts);
            })
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
like image 726
Ярослав Прохоров Avatar asked Mar 29 '19 06:03

Ярослав Прохоров


1 Answers

Another option is just to remove Register link and redirect from register to login in your Startup class:

    app.UseEndpoints(endpoints =>
        {
            endpoints.MapGet("/Identity/Account/Register", context => Task.Factory.StartNew(() => context.Response.Redirect("/Identity/Account/Login", true, true)));
            endpoints.MapPost("/Identity/Account/Register", context => Task.Factory.StartNew(() => context.Response.Redirect("/Identity/Account/Login", true, true)));
        });
like image 132
Mardok Avatar answered Sep 17 '22 21:09

Mardok