Forum Widgets
Latest Discussions
Http requests from client to server project with cookie auth
Start a new Blazor app with individual accounts. Add a controller to the server project. [ApiController] [Route("api/[controller]")] [Authorize] public class TestController : ControllerBase { private readonly ILogger _logger; public TestController(ILogger logger) { _logger = logger; } [HttpGet("public")] [ProducesResponseType(typeof(string), StatusCodes.Status200OK)] [AllowAnonymous] public IActionResult GetPublic() { return Ok(JsonConvert.SerializeObject("Now is the time for all good men to come to the aid of the public party.")); } [HttpGet("private")] [ProducesResponseType(typeof(string), StatusCodes.Status200OK)] public IActionResult GetPrivate() { return Ok(JsonConvert.SerializeObject($"Now is the time for all good men and {User.Identity.Name} to come to the aid of the private party.")); } And route it in in Program.cs ... builder.Services.AddControllers(); // + ... app.MapControllers(); // + Create a HttpClient for the API public class CookieHandler : DelegatingHandler { public CookieHandler() { InnerHandler = new HttpClientHandler() { AllowAutoRedirect = false }; } protected override Task SendAsync( HttpRequestMessage request, CancellationToken cancellationToken) { request.SetBrowserRequestCredentials(BrowserRequestCredentials.Include); request.Headers.Add("X-Requested-With", ["XMLHttpRequest"]); return base.SendAsync(request, cancellationToken); } } public class LocalHttpClient : HttpClient { public LocalHttpClient(CookieHandler h) : base(h) { } } in the <em>client</em> project and register it in <em>both</em> the client and the server project. builder.Services.AddTransient(); builder.Services.AddTransient(); Update the client side page Auth.razor to use it @page "/auth" @using Microsoft.AspNetCore.Authorization @attribute [Authorize] @* @rendermode InteractiveWebAssembly *@ @rendermode InteractiveAuto @inject LocalHttpClient _HttpClient @code{ protected override async Task OnInitializedAsync() { HttpResponseMessage rx = await _HttpClient.GetAsync("https://localhost:7131/api/Test/public"); Public = await rx.Content.ReadAsStringAsync(); rx = await _HttpClient.GetAsync("https://localhost:7131/api/Test/private"); Private = await rx.Content.ReadAsStringAsync(); if(!rx.IsSuccessStatusCode) { Private = (Private ?? "") + rx.StatusCode.ToString(); } await base.OnInitializedAsync(); } string Public { get; set; } string Private { get; set; } } <PageTitle>Auth</PageTitle> <h1>You are authenticated</h1> <p>Public: <code>@Public</code></p> <p>Private: <code>@Private</code></p> <AuthorizeView Context="AuthorizeViewContext"> Hello @AuthorizeViewContext.User.Identity?.Name! </AuthorizeView> The authorisation doesn't work.RichardB1640May 07, 2026Copper Contributor23Views0likes0CommentsGetting a ConnectionString empty error in a webapi project with .net 10
I'm running in .NET 10 with the most recent update for everything. I'm in EF. I'm ASP.NET Core. Below is my program.cs file. Inside of the program.cs file, when I call to get my connection string, I get back what I expect. When I hit the LoginController, I see the settings in the IConfiuguration that is handed in. However, when I set a breakpoint in the FSMUserStore constructor, I check the context that is handed in, and it's connection string is not set correctly (at all). I've run through Visual Studio debugger so many times, and tried so many things, I'm just lost on this. I think the problem is in how I am setting up for dependency injection in the program.cs file, but I've tried so many things that I don't know what else to try. Anyone have a suggestion? using ElmahCore.Mvc; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microsoft.IdentityModel.Tokens; using Portal.Libraries; using PortalDataModels.Models; using System.Text; using Twilio.TwiML.Voice; var builder = WebApplication.CreateBuilder(args); IConfiguration configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .AddEnvironmentVariables() .Build(); // connString get's the correct value var connString = configuration.GetConnectionString("DefaultConnection"); // Add services to the container. // For Entity Framework builder.Services.AddDbContext<PortalDataModels.Models.POA_CSMContext>(options => options.UseSqlServer(configuration.GetConnectionString(connString))); builder.Services.AddScoped<IUserStore<FSMUser>, FSMUserStore>(); builder.Services.AddIdentity<FSMUser, IdentityRole>() .AddEntityFrameworkStores<POA_CSMContext>() .AddUserManager<UserManager<FSMUser>>() .AddSignInManager<SignInManager<FSMUser>>() .AddDefaultTokenProviders(); builder.Services.AddElmah<ElmahCore.Sql.SqlErrorLog>(options => { options.ConnectionString = connString; options.SqlServerDatabaseTableName = "Elmah_Error"; //Defaults to ELMAH_Error if not set options.OnPermissionCheck = context => false; }); // Adding Authentication builder.Services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; }) // Adding Jwt Bearer .AddJwtBearer(options => { options.SaveToken = true; options.RequireHttpsMetadata = false; options.MapInboundClaims = false; options.TokenValidationParameters = new TokenValidationParameters() { ValidateIssuer = true, ValidateAudience = true, ValidAudience = configuration["Jwt:ValidAudience"], ValidIssuer = configuration["Jwt:ValidIssuer"], IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["Jwt:Key"])) }; }); builder.Services.AddScoped<UserManager<FSMUser>>(); builder.Services.AddControllers(); // Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi builder.Services.AddOpenApi(); var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.MapOpenApi(); } app.UseHttpsRedirection(); app.UseAuthentication(); app.UseAuthorization(); app.MapControllers(); app.Run();wallymMay 06, 2026Copper Contributor56Views0likes1CommentPaytmgateway integration throwing exception error
While integration paytmgateway to my asp.net project, throwing exception "exception occurred while verifying checksum. Invalid padding can't be removed. What to do? I put every data right like merchant key ,MID etc . Plz guide menaveen271336Mar 15, 2026Copper Contributor50Views0likes0CommentsBlazor parameter passed by reference
I got the impression that in Blazor parameters are always effectively passed by value which is why you need to use EventCallback for two-way binding to send a change in the parameter value back up to the component that passed it. But not so; reference types really are passed by reference. Therefore if a child component updates a parameter value that is a reference type then the value in the parent is changed and all you need to do is call `StateHasChanged` on the parent. Is this as intended? Have I misunderstood the documentation? Example: https://drive.google.com/file/d/1i1Rh36nHU1Z2voyHDtLVZ9GyziLw9AQq/view?usp=sharing (Don't seem to be able to attach here and it's not really feasible to inline a whole Blazor project.)RichardB1640Mar 04, 2026Copper Contributor187Views0likes2CommentsSharePoint List View Threshold Error while Fetching 5000+ Records in list.
I am fetching data from a SharePoint list that contains more than 5000 records inside my function. While retrieving the data, I am getting the following error: “Flow Reminders→ The attempted operation is prohibited because it exceeds the list view threshold.” Scenario: The SharePoint list has 5000+ items. Data is being fetched programmatically. The error occurs during query execution. What I need help with What is the recommended and best-practice approach to retrieve large datasets from a SharePoint list without hitting the list view threshold? Questions: What is the recommended approach to fetch large data from a SharePoint list without hitting the list view threshold? Any suggestions, examples, or documentation references would be greatly appreciated. Thanks.AjayMFeb 23, 2026Copper Contributor52Views0likes0CommentsDebug Asp.Net - "This site can't be reached"
Hello, Today, all my Visual Studio 2019 Community projects stopped debugging and are displaying the following message in the browser: "This site can't be reached." I've tried using Visual Studio 2022 Community, but the problem is the same. I have numerous projects (Asp.Net - vb), and they all have the same issue. Even creating a new project (VS 20219 or VS 2022), the error persists. I've tried reinstalling IIS Express, disabling my antivirus, and reinstalling Visual Studio 2022 (since it was just for testing). Nothing works. Everything was working until yesterday, but now I can't work anymore. It seems like a Windows update, but I don't have restore points to revert to. I'd appreciate it if anyone has any idea what this could be. EduardoSolvedEduardoFornaroDec 20, 2025Copper Contributor402Views0likes2CommentsIt appears and error that does not exist
I am using VS 2022 Community and when i develope asp.net apps it happens sometimes that it appears an error that does not exist adn only after many hours of searching for the error or rewriting the same code the app begins to run correctly. Somehitng simmilar happened to any of you ? how can i avoid these strange behaviour of the compiler ? Thank you in advance Luis MartinlmobarqDec 12, 2025Copper Contributor91Views0likes0CommentsConnect .Net (4.6.2) to Dataverse using the Dataverse plugin
Hi Microsoft Tech Community, We have a Dataverse environment in our tenant, and I have its URL. I'm building a .NET application and need to connect it to Dataverse for data access. From the Learn docs, ChatGPT, and Copilot, it seems I need to use an App ID (Client ID) and Client Secret in the connection string (e.g., via Microsoft.PowerPlatform.Dataverse.Client). However, the Dataverse environment itself doesn't expose any App ID or Client Secret—where would I even find those if they exist? Here's the code snippet we found online that's using OAuth with AppId and RedirectUri, but we're unsure about the app registration part: using Microsoft.Crm.Sdk.Messages; using Microsoft.PowerPlatform.Dataverse.Client; using Microsoft.Xrm.Sdk; class Program { // TODO Enter your Dataverse environment's URL and logon info. static string url = "https://yourorg.crm.dynamics.com"; static string userName = "email address removed for privacy reasons"; static string password = "yourPassword"; // This service connection string uses the info provided above. // The AppId and RedirectUri are provided for sample code testing. static string connectionString = $@" AuthType = OAuth; Url = {url}; UserName = {userName}; Password = {password}; AppId = 51f81489-12ee-4a9e-aaae-a2591f45987d; RedirectUri = app://58145B91-0C36-4500-8554-080854F2AC97; LoginPrompt=Auto; RequireNewInstance = True"; static void Main() { //ServiceClient implements IOrganizationService interface IOrganizationService service = new ServiceClient(connectionString); var response = (WhoAmIResponse)service.Execute(new WhoAmIRequest()); Console.WriteLine($"User ID is {response.UserId}."); // Pause the console so it does not close. Console.WriteLine("Press the <Enter> key to exit."); Console.ReadLine(); } } Do I need to create a separate app registration in Microsoft Entra ID (Azure AD), link it to the Dataverse environment (perhaps as an application user?), and then use that app's Client ID/Secret in my .NET code? If so, could someone outline the exact steps, including permissions and Power Platform admin center setup? Any guidance or links to official walkthroughs would be greatly appreciated—thanks!AjayMDec 08, 2025Copper Contributor142Views0likes0CommentsWhen should I use SQL Server, MySQL, or PostgreSQL?
I'm working on a web application (using C#/.NET backend), and I need to choose a relational database. I'm considering three options: Microsoft SQL Server MySQL PostgreSQL I want to understand: What are the strengths and weaknesses of each? Which database is better suited for: Transactional performance Advanced querying / analytics Ease of use with .NET Cross-platform support Are there any licensing or hosting concerns I should consider? My use case involves: Moderate traffic Complex queries with joins APIs and background jobs Deployment to cloud (Azure) I’d appreciate any recommendations or real-world experience comparing these databases.UdhayarajanJOct 28, 2025Copper Contributor1KViews0likes3CommentsConvert the standard Blazor navigation menu to a collapsible icon menu
While I admittedly love Blazor I’ve always changed the out-of-the-box navigation menu that comes with it. It’s the first manoeuvre I pull when spinning up a new Blazor app, stripping out the purple gradient and getting it in, what I consider, a “blank slate state”. The other change I’ve wanted to make to the out-the-box look is one of those deluxe collapsible menus that leave just the icons showing. Anyone that’s used Azure DevOps will know what I’m talking about. I’ve included a picture to show DevOps example of what I’d like to see in my Blazor app. It gives a load of extra screen real estate which is always a priority for me in business applications particularly with complex or intensive workflows. Plus it gives the user the option to remove the text prompts once they are familiar with the system which is supported with carefully selected icon choices. As with most tasks that I assume will be an obvious solution I hit my search engine of choice and looked to avoid reinventing the wheel. However I found no source of pre-written changes to achieve this and was directed to fairly expensive third party controls to solve this one for me, which, being tight fisted, pushed me to do it for myself. Here I hope you save you the trouble of paying a pretty penny or having to wrestle the CSS into submission and provide a guide for producing a nice collapsible icon navigation menu by altering the existing out of the box menu in Blazor. In the following example I have left all the standard styling as is with the menu and just done the changes required to make the collapsible menu. The three files that require changes are MainLayout.razor, NavMenu.razor and NavMenu.razor.css. The code changes are shown below: Firstly the NavMenu.razor requires a bool value (IconMenuActive) to indicate whether the icon menu is showing or not, then wrap the text of the each NavItem in an if statement dependent on this bool. Then a method for toggling this bool and EventCalBack to send a bool to the MainLayout.razor for shrinking the width of the sidebar. Lastly there needs to be the control for switching menu views (I used the standard io icon arrows). NavMenu.razor <div class="top-row ps-3 navbar navbar-dark"> <div class="container-fluid"> <span class="oi oi-monitor" style="color:white;" aria-hidden="true"></span> @if (!@IconMenuActive) { <a class="navbar-brand" href="">The Menu Title Here</a> } <button title="Navigation menu" class="navbar-toggler" @onclick="ToggleNavMenu"> <span class="navbar-toggler-icon"></span> </button> </div> </div> <div class="@NavMenuCssClass" @onclick="ToggleNavMenu"> <nav class="flex-column"> <div class="nav-item px-3"> <NavLink class="nav-link" href="" Match="NavLinkMatch.All"> <span class="oi oi-home" aria-hidden="true"></span> @if (!@IconMenuActive) { <label>Home</label> } </NavLink> </div> <div class="nav-item px-3"> <NavLink class="nav-link" href="counter"> <span class="oi oi-plus" aria-hidden="true"></span> @if (!@IconMenuActive) { <label>Counter</label> } </NavLink> </div> <div class="nav-item px-3"> <NavLink class="nav-link" href="fetchdata"> <span class="oi oi-list-rich" aria-hidden="true"></span> @if (!@IconMenuActive) { <label>Fetch data</label> } </NavLink> </div> </nav> </div> <div class="bottom-row"> <div class="icon-menu-arrow"> @if (!@IconMenuActive) { <span class="oi oi-arrow-left" style="color: white;" @onclick="ToggleIconMenu"></span> } else { <span class="oi oi-arrow-right" style="color: white;" @onclick="ToggleIconMenu"></span> } </div> </div> @code { //bool to send to MainLayout for shrinking sidebar and showing/hide menu text private bool IconMenuActive { get; set; } = false; //EventCallback for sending bool to MainLayout [Parameter] public EventCallback<bool> ShowIconMenu { get; set; } private bool collapseNavMenu = true; private string? NavMenuCssClass => collapseNavMenu ? "collapse" : null; private void ToggleNavMenu() { collapseNavMenu = !collapseNavMenu; } //Method to toggle IconMenuActive bool and send bool via EventCallback private async Task ToggleIconMenu() { IconMenuActive = !IconMenuActive; await ShowIconMenu.InvokeAsync(IconMenuActive); } } Next I add in a bit of CSS in to NavMenu.razor.css to put the arrow for toggling the menu at the bottom of the sidebar and a media query to make sure it doesn't show up in mobile view. The CSS classes added are .bottom-row and .icon-menu-arrow. NavMenu.razor.css .navbar-toggler { background-color: rgba(255, 255, 255, 0.1); } .top-row { height: 3.5rem; background-color: rgba(0,0,0,0.4); } .bottom-row { position: absolute; bottom: 0; padding-bottom: 10px; text-align: right; width: 100%; padding-right: 28px; } .icon-menu-arrow { text-align: right; } .navbar-brand { font-size: 1.1rem; } .oi { width: 2rem; font-size: 1.1rem; vertical-align: text-top; top: -2px; } .nav-item { font-size: 0.9rem; padding-bottom: 0.5rem; } .nav-item:first-of-type { padding-top: 1rem; } .nav-item:last-of-type { padding-bottom: 1rem; } .nav-item ::deep a { color: #d7d7d7; border-radius: 4px; height: 3rem; display: flex; align-items: center; line-height: 3rem; } .nav-item ::deep a.active { background-color: rgba(255,255,255,0.25); color: white; } .nav-item ::deep a:hover { background-color: rgba(255,255,255,0.1); color: white; } @media (min-width: 641px) { .navbar-toggler { display: none; } .collapse { /* Never collapse the sidebar for wide screens */ display: block; } } @media (max-width: 640px) { .bottom-row { display: block; } } Finally I add in the handler for the EventCallback to MainLayout.razor and a method to alter the width of the sidebar. MainLayout.razor @inherits LayoutComponentBase <div class="page"> <div class="sidebar" style="@IconMenuCssClass"> <NavMenu ShowIconMenu="ToggleIconMenu"/> </div> <main> <div class="top-row px-4"> <a href="https://docs.microsoft.com/aspnet/" target="_blank">About</a> </div> <article class="content px-4"> @Body </article> </main> </div> @code{ private bool _iconMenuActive { get; set; } private string? IconMenuCssClass => _iconMenuActive ? "width: 80px;" : null; protected void ToggleIconMenu(bool iconMenuActive) { _iconMenuActive = iconMenuActive; } } The final product of these little changes are shown in the pictures below: I'd love to hear if anyone has tackled this in a different way to me and if they've got any ideas on making it cleaner. Have yourselves a wonderful day, GavGavin-WilliamsSep 24, 2025Brass Contributor78KViews10likes19Comments
Tags
- ASP.NET Core161 Topics
- ASP.NET (Classic)87 Topics
- Web API69 Topics
- Blazor64 Topics
- mvc56 Topics
- Razor Pages35 Topics
- IIS.NET29 Topics
- security26 Topics
- SignalR6 Topics
- community1 Topic