Forum Widgets
Latest Discussions
Solutions for Blazor problems
Hi, I've significantly reduced render times, section rendering and configuration, API exposure, ... And I am starting thinking of sharing. I've never done this before, so I am wondering how to offer my Blazor framework API. Feacures I've implemented: Defer rendering (on standard component level - as naturalrendering pipeline) Custom sections (with custom state proagation and optimization minimizing render requests - my sections allow for full generic settings usable in section definition component with any amount of RenderFragment or other parameters): <YourSection Param1="StateWatchedParam1" Param2="StateWatchedParam2"> <RenderFragment1> StateWatchedContent with single render on whole section outlet </RenderFragment1> <RenderFragment2> StateWatchedContent with single render on whole section outlet </RenderFragment2> </YourSection> Unit of Work system with unltimited dependency tree of steps described by FluentAPI and accessed only by input model from client side - thus limiting any API exposure. You would have to know descriptor, rights and then guess allowed steps and stil only can fill model with input data - nothing more ... LinQ projector pattern with lego building FluentAPI system - where any business logic can be break into named step in specific named projector, so you are out of ordinary expression tree completely. That projector pattern is correctly written to check for Queryable Provider and to work with the same expression tree also for Enumerable. (Thus the same lego pieces can work for client.) Blazor component messagging done on direct Task API system - so without any queue or backlog. You can directly pass any data between any Blazor component and you are doing it in direct way without any delay or data transfer. Here I have SignalR also in the same system - allowing server to communicate with any component needed. And whole system is communicating with ToastLogger, thus any issue/unhandled exception can be (and it is) instantly logged and toasted to user. Background runner - thus any Task in Blazor can be called to just RunInBackground and it is immediately handled in Task lock mechanism, Exception mechanism and with correct Blazor stae update pipeline thus allowing for partial renders and mid render switch to background process finishing later and rendering from that deferred background.RickettsialPoxFeb 09, 2025Copper Contributor13Views0likes0Comments[ASP.NET CORE] Exchange Web Services Throw HTTP 401 When Called from IIS
Hi, Currently, I can't get Microsoft.Exchange.WebServices to work with Exchange 2019 On-Premise. Send Email feature is working OK on Development but as soon I deployed it to IIS, it stopped working with following error: Microsoft.Exchange.WebServices.Data.ServiceRequestException: The request failed. The remote server returned an error: (401) Unauthorized. ---> System.Net.WebException: The remote server returned an error: (401) Unauthorized. at System.Net.HttpWebRequest.GetResponse() at Microsoft.Exchange.WebServices.Data.EwsHttpWebRequest.Microsoft.Exchange.WebServices.Data.IEwsHttpWebRequest.GetResponse() at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest request) --- End of inner exception stack trace --- at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest request) at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(IEwsHttpWebRequest& request) at Microsoft.Exchange.WebServices.Data.SimpleServiceRequestBase.InternalExecute() at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute() at Microsoft.Exchange.WebServices.Data.ExchangeService.InternalCreateItems(IEnumerable`1 items, FolderId parentFolderId, Nullable`1 messageDisposition, Nullable`1 sendInvitationsMode, ServiceErrorHandling errorHandling) at Microsoft.Exchange.WebServices.Data.ExchangeService.CreateItem(Item item, FolderId parentFolderId, Nullable`1 messageDisposition, Nullable`1 sendInvitationsMode) at Microsoft.Exchange.WebServices.Data.Item.InternalCreate(FolderId parentFolderId, Nullable`1 messageDisposition, Nullable`1 sendInvitationsMode) at Microsoft.Exchange.WebServices.Data.EmailMessage.InternalSend(FolderId parentFolderId, MessageDisposition messageDisposition) I'm using same Exchange Settings (URL, Credentials, etc.) for both instance but it is only worked on Development. My Site is using App Pool User which is registered on Exchange Mailbox Users. How to fix this issue? Thanks in advance. Best Regards, HenochjazzyhackerFeb 02, 2025Copper Contributor36Views0likes0CommentsExcelDataReader and Date Field
I am looping through the Excel document saved withing my project (wwwroot) and I cannot get the date to work. I have searched and found a reference to call GetDateTime as opposed to GetValue and also attempted to use ToString() and ToShortDateString(); Cannot implicitly convert type 'string' to 'System.DateOnly' What am I missing? using (var stream = System.IO.File.Open(filePath, FileMode.Open, FileAccess.Read)) { // Auto-detect format, supports: // - Binary Excel files (2.0-2003 format; *.xls) // - OpenXml Excel files (2007 format; *.xlsx, *.xlsb) using (var reader = ExcelReaderFactory.CreateReader(stream)) { do { while (reader.Read()) { BirthModel birth = new BirthModel(); birth.LastName = reader.GetValue(1).ToString(); birth.FirstName = reader.GetValue(2).ToString(); birth.MiddleName = reader.GetValue(3).ToString(); birth.BirthDate = reader.GetDateTime(4).ToShortDateString(); birth.County = reader.GetValue(5).ToString(); birth.Maiden_FirstName = reader.GetValue(6).ToString(); birth.Maiden_MiddleName = reader.GetValue(7).ToString(); birth.Maiden_LastName = reader.GetValue(8).ToString(); } } while (reader.NextResult());jimnealkyJan 20, 2025Copper Contributor37Views0likes1CommentModule object available in .NET 6 Blazor WASM Project, but not in .NET 8+ After Upgrade
I have a working project in .NET 6 that calls the following JS code: export function synchronizeFileWithIndexedDb(filename) { return new Promise((res, rej) => { const db = window.indexedDB.open('SqliteStorage', 1); db.onupgradeneeded = () => { db.result.createObjectStore('Files', { keypath: 'id' }); }; db.onsuccess = () => { const req = db.result.transaction('Files', 'readonly').objectStore('Files').get('file'); req.onsuccess = () => { Module.FS_createDataFile('/', filename, req.result, true, true, true); res(); }; }; }); } And behind the scenes in OnInitializedAsync: if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("browser"))) { // create SQLite database file in browser var module = await _js.InvokeAsync<IJSObjectReference>("import", "./dbstorage.js"); await module.InvokeVoidAsync("synchronizeFileWithIndexedDb", SqliteDbFilename); } This works perfectly in .NET 6, which is unfortunately now EOL. Simply upgrading it to .NET 8 causes "Module" (see line 11) to no longer be defined. I ran into the same problem using a brand new .NET 9 project as well. If it's .NET 6 it works, .NET 8 or higher it breaks. Is this a known issue? I'm afraid of upgrading anything with JS Interop now 😛 Is there a path forward? I tried changing Module to DotNet, based on reading MSFT docs, but that didn't work. I don't want to go back to .NET 6 to solve this if I don't have to :) You can try it yourself simply by upgrading the following Sqlite WASM project: TrevorDArcyEvans/BlazorSQLiteWasm: Blazor + EF Core + SQLite + WASM All running in a browser together! What could possibly go wrong?SolvedAuri_RahimzadehJan 18, 2025Copper Contributor32Views0likes1CommentAdding an Icon to the iPhone HomeScreen disables Blazor Server re-connection indefinitely.
When I use my Blazor Server app (.NET 8) with Safari on my iPhone, I am asked to Reconnect to the Server when the connection is lost. I swipe down and a connection is re-established. If I make an Icon on the iPhone Home Screen (mimicking an iPhone app) I am unable to re-establish a Connection. Swiping down to refresh the page does nothing. Is there a solution for this via Blazor Server? Thank youSolvedAxium7Jan 04, 2025Copper Contributor27Views0likes1CommentI want to use VS code instead of Visual Studio for .Net Framework 3.5 or .Net Framework 4.8 project
I’m transitioning from Visual Studio to Visual Studio Code for .NET Framework 3.5 and 4.8 projects but facing difficulties with: Debugging: Setting up a debugger for seamless support. Resource Files (.resx): Editing/viewing with auto-generation of designer files. DBML Files: Managing these and their designer files effectively. How to execute the Unit tests? Are there any extensions, workflows, or best practices in VS Code to handle these issues?puneet_groverDec 27, 2024Copper Contributor44Views0likes0CommentsMulti-project launch profiles not working
Hi, I am using Visual Studio 2022 (version 17.12.3) for an ASP.NET + React project. I want to take advantage of the new launch profiles feature to have multiples profiles for http and https, edge and chrome, etc. The feature is enabled, and I am able to create my profiles. So far so good. I have even ticked the share box so a .slnLaunch has been created. But when I am back to the main VS screen, I don't have the dropdown list in my toolbar to chose the profile to launch. I just have the old tooldbar : I tried to : Restart VS Restart my PC Disable/enable the feature with VS restarts in between Sorry for the screenshots in french btw ;) Thanks in advance !AlexTekeufDec 05, 2024Copper Contributor99Views0likes0CommentsReact website with ASP.NET and IIS : API not working
Hi, I have found a lot of similar issues on the web but none was working for me, and I am so desperate after days so I am posting here and hope someone can help. I have an ASP.NET server that serves a React website, and also works as an API for the website itself. The server runs on a Windows 11 PC with IIS, in C:/MyWebSite. This folder contains the ASP.NET server (.exe, .dll, etc), the IIS configuration (web.config) and the build React website (index.html, favicon.ico and assets folder). The server succeed to show my main page, but it fails doing an API request. The API request fails as well when I call it from Postman, and gives me the error "HTTP 404.0 - Not Found" with these details : Module IIS Web Core Notification : MapRequestHandler Handler : StaticFile Error code : 0x80070002 FYI, the request is GET http://localhost:5058/api/configuration/settings Concerning ASP.NET, here is my Program.cs : using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.IdentityModel.Tokens; using System.Text; // Create the web application builder var builder = WebApplication.CreateBuilder(args); // JWT authentication builder.Services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(options => { string? tKey = builder.Configuration["Jwt:Key"]; options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = builder.Configuration["Jwt:Issuer"], ValidAudience = builder.Configuration["Jwt:Audience"], IssuerSigningKey = tKey != null ? new SymmetricSecurityKey(Encoding.UTF8.GetBytes(tKey)) : null }; }); // Add the controllers to the application (for input http requests) builder.Services.AddControllers(); // Configure CORS policy builder.Services.AddCors(options => { options.AddPolicy("AllowAllOrigins", builder => { builder.AllowAnyOrigin() .AllowAnyHeader() .AllowAnyMethod(); }); }); // Create the App var app = builder.Build(); // Applies the CORS policy app.UseCors("AllowAllOrigins"); // Serving the static files app.UseDefaultFiles(); app.UseStaticFiles(); app.UseRouting(); // Map the routes to the controllers app.MapControllers(); // Undefined route will lead to index.html app.MapFallbackToFile("index.html"); // Run the App app.Run(); Of course, I have created some controllers, here is ConfigurationController.cs for example : using Microsoft.AspNetCore.Mvc; namespace AspReact.Server.Controllers { [ApiController] [Route("api/configuration")] public class GeneralController : ControllerBase { [HttpGet("settings")] public ActionResult GetSettings() { return Ok(new { language = 'fr', theme = 0 }); } [HttpPost("settings")] public ActionResult SetSettings([FromQuery] string language, [FromQuery] string theme) { m_tLanguage = language; m_tTheme = theme; return Ok(); } } } Here is my IIS configuration : <?xml version="1.0"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="React Routes" stopProcessing="true"> <match url=".*" /> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" /> </conditions> <action type="Rewrite" url="/" /> </rule> </rules> </rewrite> </system.webServer> </configuration> NB : At first I was not doing : <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" /> And the API request was returning the content of index.html... If it can help. Please note that all this is working during development with the server running in a debug console. I would be grateful for any help! Thanks.SolvedAlexTekeufDec 05, 2024Copper Contributor130Views0likes2CommentsMultiple ASP.NET Core Web API instances runs only once
I have an ASP.NET Core 8.0 Web API hosted on two IIS applications (app-1 and app-2) under the Default Web Site on a Windows 11 OS. Both IIS applications point to the same physical path (inetpub\wwwroot\myapp) and each application has its own dedicated application pool (app1 and app2). The application pools have unique identities (app1svc and app2svc), both of which are members of the Administrators group. In the Web API, I have an AppEvents class implementing IHostedService, with StartAsync and StopAsync methods to handle application start and stop events. In the Program.cs, I register it using builder.Services.AddHostedService<AppEvents>(). When accessing http://localhost/app-1, the StartAsync method is triggered as expected. However, when accessing http://localhost/app-2, the StartAsync method does not execute. It seems that the application starts only once, despite both IIS apps pointing to the same physical directory. I've tried changing the AspNetHostingModel from InProcess to OutOfProcess, but the behavior remains the same. Is there a way to deploy multiple instances of the same web app, each running separately but pointing to the same physical directory, so that each instance correctly triggers its own StartAsync?AdryoneDec 02, 2024Copper Contributor43Views0likes0CommentsIs it possible to run a asp.net core site within testing?
Hi! I'm trying to write tests for a small minimal API based on asp.net core. I don't want to test over the internet, but start the app within the tests and call the endpoints on the running site. Is this possible? And how? Should I use TestServer for this? I'm new to writing tests, so maybe it's an easy issue to code. Thanks! :)SLTechNov 22, 2024Occasional Reader14Views0likes0Comments
Resources
Tags
- ASP.NET Core144 Topics
- ASP.NET (Classic)76 Topics
- Web API61 Topics
- Blazor58 Topics
- mvc53 Topics
- Razor Pages35 Topics
- security26 Topics
- IIS.NET26 Topics
- SignalR5 Topics
- Community1 Topic