IIS.NET
29 Topicsaspnet c# iterate control in listview and remove a panel from placeholder in one column
trying to iterate through controls in listview to remove panel01 from placeholder if detected row in database condition dt.Rows[i]["BidEndWithError"].ToString() == "no" in the row: But all the listview's panel01 being removed even dt.Rows[i]["BidEndWithError"].ToString() == "no" is not 'no'`your text` `<asp:PlaceHolder ID="phLabel" runat="server"> <asp:Panel ID="panel01" runat="server"> Day Left : <%# Eval("BidDayLeft") %></br> Hour Left : <%# Eval("BidHourLeft") %></br> Minute Left : <%# Eval("BidMinuteLeft") %></br> Second Left : <%# Eval("BidSecondLeft") %></br> </asp:Panel> protected void lv01_ItemDataBound(object sender, ListViewItemEventArgs e) { if (e.Item.ItemType == ListViewItemType.DataItem) { string constr = ConfigurationManager.ConnectionStrings["bidsystemdb"].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { DataTable dt = new DataTable(); //string strSQL = "Select * from BidTable2 WHERE ProductName='Toy 1'"; string strSQL = "Select * from BidTable2"; SqlDataAdapter adpt = new SqlDataAdapter(strSQL, con); adpt.Fill(dt); for (int ij = 0; ij < e.Item.Controls.Count; ij++) { for (int i = 0; i < dt.Rows.Count; i++) { //Response.Write("lv01 reached!"); if (dt.Rows[i]["BidEndWithError"].ToString() == "no") { Response.Write("lv01 level 2 reached!"); PlaceHolder _phLabel = e.Item.Controls[ij].FindControl("phLabel") as PlaceHolder; Panel _pnlLabel = e.Item.Controls[ij].FindControl("panel01") as Panel; _phLabel.Controls.Remove(_pnlLabel); ContentPlaceHolder _MainContent = Master.FindControl("MainContent") as ContentPlaceHolder; UpdatePanel _udp01 = _MainContent.FindControl("udp01") as UpdatePanel; _udp01.Update(); } } } } } }`11Views0likes0CommentsBuild Scalable Web Apps and APIs with ASP.NET Core, Blazor, Angular for Modern Web Apps
I’m starting this discussion because many developers today need guidance on how to build modern, scalable web applications and APIs by combining ASP.NET Core, Blazor, and Angular—three powerful technologies within the .NET ecosystem. Whether you're focused on server-side development, creating dynamic client-side apps, or integrating both, these frameworks provide incredible capabilities to enhance your projects ASP.NET Core for API Development: ASP.NET Core is a robust, high-performance framework that allows you to create powerful APIs. Some of the best practices we’ll cover include: - Designing RESTful APIs with ASP.NET Core - Utilizing Entity Framework Core for efficient database access - Securing APIs with JWT and OAuth - Handling asynchronous requests for optimal performance - Implementing API versioning and changes over time Building Dynamic Web Apps with Blazor: Blazor enables you to create interactive web applications using C# instead of JavaScript. We will discuss: - Blazor Web Assembly vs. Blazor Server: Differences and use cases - Creating reusable Blazor components for UI - Integrating third-party JavaScript libraries with Blazor - Using SignalR for real-time features - Optimizing Blazor for performance Angular for Full-Featured Client-Side Development: Angular is a powerful, full-featured front-end framework that excels in creating dynamic and complex user interfaces. In this section, we'll dive into: - Why you might choose Angular over Blazor in certain cases - Using Angular CLI to scaffold, build, and maintain apps - Managing state in Angular with NgRx or RxJS - Connecting Angular with ASP.NET Core APIs for data handling - Working with Angular components, services, and routing for a seamless user experience Combining Angular and Blazor in a Single Application: You may have use cases where you want to combine both Blazor and Angular in one application to leverage the strengths of each framework: - When to use Angular for complex frontend features (e.g., dynamic forms, complex data visualization) and Blazor for simpler components or backend-heavy apps. - Managing communication between Angular and Blazor components in a single page (e.g., using - JavaScript Interop to pass data between the two). - Handling authentication and state management across both frameworks. Integration between Frontend (Blazor/Angular) and Backend (ASP.NET Core): No matter whether you're using Angular or Blazor for the frontend, integrating these with your backend API is key. We'll discuss: - Setting up HttpClient for making API calls from both Blazor and Angular - Working with SignalR to enable real-time features in both frontends - Managing authentication and authorization across both Angular and Blazor (JWT, OAuth) - Best practices for passing data and sharing state between the frontend and backend Scalable and Maintainable Web Apps: When building full-stack web applications, it's important to focus on scalability and maintainability. Here are some practices for achieving this: - Structuring your application code to separate concerns (e.g., services, components, repositories) - Utilizing Dependency Injection for flexible and testable code - Modularizing your codebase for easier updates and maintenance - Using Lazy Loading for Angular and Blazor components to improve performance - Leveraging Caching strategies to enhance response times Testing and Continuous Deployment: For any modern application, testing and deployment are crucial. We’ll discuss: - Unit and integration testing in ASP.NET Core, Blazor, and Angular - Automated end-to-end testing (e.g., with Cypress for Angular, bUnit for Blazor) - Continuous Integration/Continuous Deployment (CI/CD) strategies for seamless deployment to cloud platforms like Azure or AWS When to Choose Angular, Blazor, or Both: It’s essential and interesting to know when to use each of these frameworks depending on your project’s needs. Some scenarios we’ll explore: - When to go for Blazor for a unified C# experience in both frontend and backend - Why you might opt for Angular when building highly interactive, feature-rich web applications - Hybrid approaches where you can use Blazor and Angular together for a robust full-stack solution SO: Combining ASP.NET Core, Blazor, and Angular allows developers to choose the right tool for the right job, creating flexible, scalable, and maintainable web applications. Whether you’re leveraging Blazor for its deep integration with .NET or Angular for its powerful frontend capabilities, these technologies offer a powerful suite of tools to build modern web applications. What are your thoughts? How have you integrated Angular or Blazor with ASP.NET Core in your projects? Share your experiences and challenges, and let's collaborate on solutions!288Views8likes2CommentsHow to stop "A potentially dangerous Request.Path" with "<"
Hello, I've been getting "A potentially dangerous Request.Path value was detected from the client (<)." recently and it is causing the application pools in IIS to stop working. The url they are trying to pass through is similar to this: https://test.com:443/cds/pubs/bib/<my_tag_9ac1214b650a30718aced57527fd64c4/> If users can past this URL at any point on my site, how can I stop it from constantly stopping my site and still being safe from SQL injection, Cross Site Scripting or some other vulnerability? Can I encode it before the page is processed so "<" becomes "<"? That way this will not be considered a dangerous Request.Path. Thank you105Views1like0Comments[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, Henoch111Views0likes0CommentsReact 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.Solved321Views0likes2CommentsMultiple 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?68Views0likes0CommentsDockerize 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.136Views0likes0CommentsDeploy 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?359Views0likes0CommentsVirtual 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!313Views0likes0CommentsDeploy .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 luck411Views0likes0Comments