Closed zackmorgs closed 4 years ago
@zackmorgs thanks for contacting us.
Can you provide us with a bit more detail on what steps did you took to get into this situation? Did you create a new project and scaffold-ed it right away?
@javiercn Sure! Thanks for your reply you're really helping me out.
I had a project I was already working on that had Identity in it from the start. Here is startup.cs
namespace BridgingCalendar
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
// add SQL to server using ApplicationDbContext
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDbContext<EventDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
// add Indentity to server, save it to the database
// also: add Roles configuration boilerplate (admin, user)
services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddRoles<IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>();
// was told to add this after scaffolding Identity: https://docs.microsoft.com/en-us/aspnet/core/security/authentication/scaffold-identity?view=aspnetcore-3.1&tabs=visual-studio
services.AddControllersWithViews();
services.AddAuthorization(config =>
{
config.AddPolicy("Admin", policy => policy.RequireClaim("Admin", "moderator", "superuser"));
});
//services.AddScoped<AuthenticationStateProvider, RevalidatingIdentityAuthenticationStateProvider<IdentityUser>>();
// services.AddSingleton<WeatherForecastService>();
//services.AddSingleton<EventDbContext>();
services.AddScoped<EventService>();
services.AddScoped<AppointmentTaskService>();
// add Razor and Blazor
services.AddRazorPages();
services.AddServerSideBlazor();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
// AUTH configure
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
endpoints.MapControllers();
});
}
}
}
`
@mkArtakMSFT can you look in to this?
Thanks for the details, @zackmorgs. I'm still not clear about the scenario. Which of these options describes your situation:
Sure sorry if I wasn't clear! Of those options, "I have a properly running Blazor app, and after scaffolding Identity UI it now fails" is most definitely the predicament I am in.
Can you share a repo?
Sure, I've made it public just to fix this issue. https://github.com/zackmorgs/bridging-calendar
Any help on this would be amazing. Idk if you guys have the time to look at my project but any input on it would be great. I'm new to blazor and am making an app for a company simultaneously. I am very stuck here.
Thanks in advanced @HaoK!
@zackmorgs the link to bridging-calendar doesn't work anymore, did you rename it?
Sorry it took me forever to respond to this. This issue is closed. I got some wonderful person on Fiver to fix it for $20.
If anyone else ends up here, try what he said because it worked for me.
He told me to follow this comment trail here: https://github.com/dotnet/aspnetcore/issues/13120#issuecomment-531456072
Glad to see you resolved this
I am experiencing a strange bug after scaffolding identity for a blazor project. After scaffolding all the items or really any of them, I get this error:
**An unhandled exception occurred while processing the request.** _NotSupportedException: Specified method is not supported. Microsoft.AspNetCore.Mvc.RazorPages.PageBase.EnsureRenderedBodyOrSections()_
StackMicrosoft.AspNetCore.Mvc.RazorPages.PageBase.EnsureRenderedBodyOrSections() Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderLayoutAsync(ViewContext context, ViewBufferTextWriter bodyWriter) Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context) Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, string contentType, Nullable<int> statusCode) Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, string contentType, Nullable<int> statusCode) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|29_0<TFilter, TFilterAsync>(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext<TFilter, TFilterAsync>(ref State next, ref Scope scope, ref object state, ref bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters() Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync() Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker) Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger) Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware.Invoke(HttpContext context) Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext) Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext) Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
Hopefully that doesn't look like gibberish. I really need this fixed and need to know how. I am new to blazor and the last five years of .net development so I don't know how to fix this. Anyways, if I can get help on this for my project that would be great because currently I can't do anything on the project unless this bug gets fixed.
Let me know what other source code you may need. I can show the repo to someone if they are willing to take a look at it.