asp.net (classic)
79 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.Solved87Views0likes2CommentsHow to increase session timeout
Hello Everyone, I am working on .NET framework 4.8 with a MVC web application. To login I am using MFA with microsoft's openid-configuration method. When I create FormsAuthenticationTicket and try to set session timeout as per my requirement but it doesn't work. See the sample code as below FormsAuthenticationTicket ticket1 = new FormsAuthenticationTicket( 1, // version adminEmail, // get username from the form DateTime.Now, // issue time is now DateTime.Now.AddDays(365), true, // cookie is not persistent "XXXXX" // role assignment is stored in userData ); But it is not working properly, it gets timeout within 15 mins41Views0likes0CommentsASP.NET Community Standup - Blazor App Testing with Playwright
Learn how to use Playwright to implement end-to-end testing for your Blazor application! Community Links: https://www.theurlist.com/blazor-standup-2023-03-14 Featuring: Jon Galloway (@jongalloway), Debbie O'Brien (@debs_obrien), Mackinnon Buck (@MackinnonBuck) #Blazor #Playwright #dotnet1.6KViews0likes0CommentsGet started with Microsoft Graph .NET SDK!
This is the first week of Hack Together: Microsoft Graph and .NET! Join the hacking🚀: https://aka.ms/hack-together/ In this session you'll learn: - What is Microsoft Graph? - What kind of information can you get using Microsoft Graph? - How to call Microsoft Graph APIs? - How to use Microsoft Graph in .NET apps, See us get started, setup auth, connect to Microsoft Graph and interact with it to tap into organizational data and insights on Microsoft 365! Please visit here for more details: https://aka.ms/hack-together1.4KViews0likes0CommentsLatest ASP.Net
Hello All, I've been working on a web application developed in ASP.Net and .Net Framework 4 for a few years. Trying to find out the new technologies that replaced asp.net web forms to brush up the skill set, found that ASP.Net Core is the new one. I've worked on ASP.Net MVC framework. Does this core completely replaced asp.net? Can the web forms applications be created in core? What is the latest framework to develop web apps? Thanks86Views0likes1CommentOpenstreet maps on azure websites
Hi, I am at the beginning of starting my own project. I come from a database tech background and have not kept up to date with all the Web frameworks. The project will run on azure and I will use visual studio. I need to be able to access opensteet maps for mapping and coordinates. So what I need to do is go to open street maps. Click somewhere on the map and a special tag should come up which I am populating in c# based on coordinates and country. I will to do the same on android, ios. Is xanarin my best option here? So there is MVC, the new .net core, web forms, some other framework. I didn't particularly like the .net core as there seems to be no designer with toolbox and components. Or do I use umbraco framework. I also saw a project called OSMsharp on github. What .net tech should I go for asI have to use openstreetmap and no Google maps, am i limited by this?. Thank you! Panos120Views0likes0CommentsHow to create a customer plugin using dotnet 6.0
Hi, I implement a base application ( a standard app), now i want to create a customer plugin inherited from the base app, My goal is to linked between there and implement the new features in the customer plugin without touch the base app. Thanks206Views0likes1CommentHow can I connect to web services (ASMX) over HTTPS from a Windows application?
We have an old web service (CustomWebService.asmx) that was created many years ago, and we have a custom Windows application installed on each user's laptop, which consumes CustomWebService.asmx via HTTP. Recently, we upgraded from HTTP to HTTPS, and then we realized that the Windows application cannot create an SSL/TLS secure channel to communicate with CustomWebService.asmx. However, connecting to the web services on MS Edge over HTTPS works well. Here is the code: WebReferenceToWebService.CustomWebService websvc = new WebReferenceToWebService.CustomWebService(); websvc.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials; websvc.PreAuthenticate = true; websvc.Url = _strWebUrl; DataSet result = websvc.GetData(); Here is the exception stack: The request was aborted: Could not create SSL/TLS secure channel. at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request) at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request) at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) The code is currently running on .NET Framework 4. Can you please advise on how to make the custom window application requests communicate with CustomWebService.asmx over HTTPS? Thanks a lot!!!205Views0likes0CommentsDockerize 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.114Views0likes0CommentsCombine Google Authentication & JWT Tokens using Cookie Authorization
* Edit: project is only a web-api, front-end will be developed in react(next.js) Hi guys! I'm a TypeScript Fullstack developer and I'm new to .NET and ASP.NET and basically this is one of my first projects using C# and .NET. My project's architecture requires a kind of different than out-of-the-box way of identifying users. I want Google Authentication which will create a local account (which I can relate other entities to) And JWT Tokens (access, refresh) generated and sent as cookies to the client and each protected endpoint to be using these cookies to authorize the requesting user. I haven't figured out a way of implementing this and still using mostly OOTB tools in order to keep modifications little as possible. Any tips and tricks on how to implement it? * Edit2: Just to be clear, I know how to create endpoints, and protected endpoints using the built in identity framework, using roles, etc... Its this combination of Google Auth, generating tokens, sending them to client as cookies basically is where my difficulty relies. * I have almost a blank new project, already set up with only google credentials355Views0likes3Comments