ASP.NET (Classic)
75 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.50Views0likes0CommentsHow 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 mins37Views0likes0CommentsLatest 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? Thanks85Views0likes1CommentOpenstreet 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! Panos118Views0likes0CommentsHow 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!!!185Views0likes0CommentsDockerize 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 credentials355Views0likes3CommentsA few issues with ASP.NET, HTML, and CSS.
What I am trying to do - Get the div #menu to display menu in the center (horizontally and vertically) between and not past (horizontally and vertically) the logo images. Basically, center horizontally and vertically between the two logo images without going further then them... - Figure out why there is such space between the content div and the footer. No clue but there is some white space and I am not sure where it is coming from. Here is some of the code... <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="Corp_Template_2.Site1" %> <!DOCTYPE html> <html> <head runat="server"> <title>Corp Template 2</title> <link rel="stylesheet" type="text/css" href="~/StyleSheet1.css" /> <asp:ContentPlaceHolder ID="head" runat="server"> </asp:ContentPlaceHolder> </head> <body> <form id="form1" runat="server"> <div id="HeaderContainer"> <div id="HeaderLogo"> <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Media/Corp Logo Sample Test.jpg" Width="200px"/> </div> <div id="MainTile" > <asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/Media/Corp Logo Sample Test.jpg" Width="200px"/> </div> <div id="Menu"> <asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1" Orientation="Horizontal" StaticDisplayLevels="2"></asp:Menu> <asp:SiteMapDataSource runat="server" ID="SiteMapDataSource1"></asp:SiteMapDataSource> </div> </div> <div id="MainContentPlaceHolder1"> <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"> </asp:ContentPlaceHolder> </div> <div id="Footer"> <h4 style="color: white;">This is the footer.</h4> </div> </form> </body> </html> As for CSS.. Here it is. body { } #Footer { width: auto; height: 75px; background-color: black; } #HeaderContainer { overflow:hidden; } #HeaderLogo { width: 200px; float: left; } #MainTile { width:200px; float: right; } #Menu { margin-left: 200px; margin-right: 200px; display: flex; justify-content: center; text-align: center; } #TestBar { width: 100%; height: 100px; background-color: silver; } #MainContentPlaceHolder1 { min-height: 550px; border: 5px solid black; } Any ideas or suggestions? Thank you very much. -Cr8tive244Views0likes1CommentWho here still uses DNN? DotNetNuke!
I was searching around the web earlier today looking for the ASP.NET Forums and found out that they are no longer around. Long ago, in a galaxy far far away, that is where it all started. DotNetNuke was bred in those forums, sad to see that they have gone by the wayside. I've still got a handful of DNN sites up and running including my personal site at https://www.chrishammond.com/228Views0likes0Comments