IIS.NET
25 TopicsReact 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.Solved86Views0likes2CommentsMultiple 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 (app1andapp2). The application pools have unique identities (app1svcandapp2svc), both of which are members of the Administrators group. In the Web API, I have anAppEventsclass implementingIHostedService, withStartAsyncandStopAsyncmethods to handle application start and stop events. In theProgram.cs, I register it usingbuilder.Services.AddHostedService<AppEvents>(). When accessinghttp://localhost/app-1, theStartAsyncmethod is triggered as expected. However, when accessinghttp://localhost/app-2, theStartAsyncmethod 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 theAspNetHostingModelfromInProcesstoOutOfProcess, 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?26Views0likes0CommentsDockerize App based .NET Framework 4.6.1
I have a Rest API based on .Net framework 4.6.1 I want to dockerize this API, but the problem is that I can't find a solution? All the solutions I found are almost all dedicated to other versions, for example, version 4.6.2, 4.7.0 etc. Can anyone recommend me the base image that I can use to build this application? I used mcr.microsoft.com/dotnet/framework/aspnet:4.8 but it is not suitable for my project.114Views0likes0CommentsDeploy an application that uses BackgroundService on IIS
As the title suggests, I have a webapi project deployed on IIS. The project has a simple timed background task that needs to be executed in the early hours of the day. I used BackgroundService to develop this functionality, I checked the execution logs and found that this background task was not executed correctly during this time, the strange thing is that it is always triggered correctly in the development environment. Later I realized that it should be related to the Idle Time-out of the IIS application pool. In the early hours of the morning, my site is not visited, so the site should be “hibernated”, so my background task can not be triggered correctly. I can only deploy the site using IIS, but I still need the background tasks, what should I do?274Views0likes0CommentsVirtual path maps to another application
First, I'm not sure if I am in the correct Forum please direct to proper forum if it is wrong. I'm am getting the following error when I run my VS2019 WCF app. (Note it was originally written in VS2019) The virtual path '/MyApp/MyService.svc' maps to another application, which is not allowed. Now, the app was working before, I think I upgraded to VS 2019 16.11.35 and this issue started to occur but I'm not sure. I have IIS 10 Express installed. I am lost why this is happening now. Can anyone offer insights or solution to this issue? Thank you!280Views0likes0CommentsDeploy .net core 7 to IIS with SignalR
I am using .net core 7. I enabled IIS on my local pc. then publish the files to the inetpub folder, and configured everything. the http requests are working and I can see the website on localhost:5151, the problem the SignalR requests not working,and I dont know whats the problem and how can I solve it? on visual studio everything works as expected. also installed the dotnet 7 hosting bundle... I tried older solutions that I saw here on stack overflow like updating the web.config file without luck372Views0likes0CommentsASP.Net Core 6 Web App - Fails to connect to database after published to on-prem IIS
Dear Community, I started to learn .Net core and entity framework, and its great. I built a small webapp as a test with a database (SQL LocalDB) and locally on my dev machine, it works fine. I publish to a folder location, then copy locally to a Windows 2019 Server and added a website on the server's IIS. The app will run the razor pages without a model, but the page that serves the model to add data or view data from the SQL database fails and the error is weird and it says there is no server found and cannot authenticate NT Authority\System. I made sure that SQL server express is installed and I can connect, I made sure localDB was added as a feature to the sqlexpress instance, etc., etc., My question is, do I have to do anything funky like wear a foil paper hat, to get this to work? I cant seem to find any documentation at all and youtube tutorials go through all the motions except publishing the app. Any help will be greatly appreciated.5.5KViews1like5CommentsBlazor Web App runs perfectly locally but not when uploaded to a live server.
I've created a Blazor Web App that allows a user to select from folder a text file. They then click a submit button that sends the text file to the chat gpt API, which, after about 30 seconds or so, sends a reply back that the user can then copy it via a button. This all works correctly when I run it locally on my computer. When I upload it to the server that hosts my site and run it from the live site, I can select one of the text files, but it no longer sends it to the API to be processed. According to the servers support, everything is fine on their end so its my code. I'm very new to this and for the life of me, I cannot find why it doesn't work on the live server when it works locally. Any suggestions would be greatly appeciated.1.1KViews0likes0CommentsSession values lost on switching server with statesession in asp.net webform with webfarm blue/green
Hi, I have an asp.net webform website implementing blue/green architecture to get smooth deployment. The blue/green is a webfarm using ARR in IIS 10 and the website use ASP.NET State Service. The site blue and green are on the same server (same IIS) as the ASP.NET State Service. The web.config contains the correct configuration to get the webfarm work correctly <sessionState mode="StateServer" stateConnectionString="tcpip=loopback:42424" cookieless="false" timeout="20"/> MachineKey and validationkey identical When we swap the blue/green website, the user can smoothly continue his navigation on the website (same sessionid used by the user on both website each time we swap). However, the values in the session do not follow up. They seem to becompartmentalised by each website. I finally found a possible explanation stating that in a webfarm, the website should have the same ID so the session values follow.Load-Balanced IIS 7.5 Web Server ASP.NET Session State problem - Server Fault My problem is that I can't have the 2 websites having the same ID because they are in the same IIS (same server). Is there any workaround or setting I can change to correct that behaviour? Thank you,1.5KViews0likes5CommentsVS 2022 + .NET Core 3.1 Web app can't debug under IIS profile
I receive the following error when trying to debug the .net core web app under the IIS profile. launchSettings.json is as follows and the PC IP is correct. (192.168.31.107) "cqrs" site is also created in IIS and with a separate app pool (CLR version: No managed code) The URL (http://192.168.31.107/cqrs/swagger/index.html) also works when typed into the browser. The only issue is when hit F5 from VS 2022 I get the popup error and can't debug. Hope this info is enough for you to let me know how to fix this. Please don't hesitate to ask for more info, I'll be happy to provide it. If I change theapplication URLto "http://localhost/cqrs" then the VS2022 lets me hit F5 and debug. But I want the web app to run with the IP, not withlocalhost. I found asimilar questionand tried everything. Nothing works. Thanks again.1.4KViews0likes3Comments