ASP.NET (Classic)
84 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(); } } } } } }`11Views0likes0CommentsEnable .Net ImageFormat.WebP in VS 2022 Prof ASPX Web.Config
Hi. I am developing C# ASPX Web sites in VS Professional 2022 (64 bit). I want to access the System.Drawing.Imaging.ImageFormat.WebP property so I can manipulate WebP files. I believe this requires .Net 4.8. I know there are 3rd party libraries out there - I would prefer to keep as much native MS code as possible. I am unable to get System.Drawing.Imaging.ImageFormat.WebP as a selection option for the ImageFormat. I can get all of the other formats e.g. TheImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg/Gif/Png etc. WebP is not shown as an option. I have Web.Config set as: <compilation optimizeCompilations="true" debug="true" targetFramework="4.8.1"> <assemblies> <add assembly="System.Net, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /> <add assembly="System.Numerics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /> </assemblies> </compilation> <httpRuntime targetFramework="4.8.1" executionTimeout="240" maxRequestLength="20480" requestValidationMode="2.0" /> The Targeting Packs & SDK seem to be installed & enabled as per the screen snap below. Any help in resolving this is greatly appreciated. Many thanks, Peter.37Views0likes0CommentsBuild 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!288Views8likes2CommentsC# code causing XSS vulnerability
Hello, We get a vulnerability scan that is show that one of my pages is susceptible to a XSS attack. We are using a telerik tree view to display different data when the nodes are expanded. This is the information they reported back to me. Issue Detail The value of the scrollPosition JSON parameter within the ctl00_ContentPlaceHolder1_VIndex2_tvIndex_ClientState parameter is copied into the HTML document as plain text between tags. The payload sbi7s<script>alert(1)</script>tx52l was submitted in the scrollPosition JSON parameter within the ctl00_ContentPlaceHolder1_VIndex2_tvIndex_ClientState parameter. This input was echoed unmodified in the application's response. Request older1_VIndex2_tvIndex_ClientState=%7b%22expandedNodes%22%3a[]%2c%22collapsedNodes%22%3a[]%2c%22logEntries%22%3a[]%2c%22selectedNodes%22%3a[]%2c%22checkedNodes%22%3a[]%2c%22scrollPosition%22%3a%220**sbi7s%3cscript%3ealert(1)%3c%5c%2fscript%3etx52l**%22%7d&ctl00_RadWindowManager1_ClientState=&__ASYNCPOST=true&ctl00%24ContentPlaceHolder1%24VIndex2%24btnAddCart=Add%20To%20Cart Response > HTTP/2 200 OK > Cache-Control: no-cache > Pragma: no-cache > Content-Type: text/plain; charset=utf-8 > Expires: -1 > Server: Microsoft-IIS/10.0 > X-Powered-By: ASP.NET > X-Frame-Options: SAMEORIGIN > X-Ua-Compatible: IE=edge,IE=11,IE=10,IE=9,IE=8,IE=7 > Strict-Transport-Security: max-age=31536000 > Date: Wed, 19 Mar 2025 16:26:27 GMT > Content-Length: 82 > 68|error|500|0**sbi7s<script>alert(1)</script>tx52l** is not a valid value for Int32.| What is the best way to pinpoint this issue? How do I fix this so it isn't showing up on the scans?Solved86Views0likes3CommentsHow 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 you105Views1like0CommentsASP.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.4KViews0likes0CommentsI 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?118Views0likes0CommentsReact 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.Solved321Views0likes2Comments