|
Hello,
I am looking for an approach sanitize all string coming from the browser to my application where I won't have to modify all action methods on all controllers.
Maybe add a filter on the controller itself?
Welcoming suggestions.
Thank you!!
|
|
|
|
|
That seems like a bad idea to me. You shouldn't be storing "sanitised" values; you should be storing the raw values, and encoding them properly when you output them. The encoding will vary depending on where you're outputting them, so storing a single "sanitised" version of the value wouldn't help.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Yes, I want to encode when I am outputting but wondering whether there is a way where I change once and it applies everywhere.
I had the OnActionExecuted filter in mind but feel like there could be a better way.
|
|
|
|
|
Apologies if you've seen this before in the Net Core section ( deleted now ), I decided here is a better fit
How can I freeze the column header row of a table so that its always visible ?
Despite googling for hours I can't find a way to do this, I wan't the table header to be frozen ( as you can do in Excel ) any ideas guys ?
"Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP
|
|
|
|
|
Add position:sticky;top:0; to the cells in the table header:
.table-frozen thead th,
.table-frozen thead td {
position: sticky;
top: 0;
background: white;
} (The background colour is required to prevent the body cells from bleeding through when the table is scrolled.)
Unfortunately, you can't apply it to the <thead> or <tr> :
Position Sticky and Table Headers | CSS-Tricks - CSS-Tricks[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Tried that Richard but no joy, there is a navbar above the table that maybe has some bearing on things
Edit
I commented out the navbar and your solution works - I have the navbar always visible and fixed to the top so it must be interfering
"Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP
modified 24-Feb-22 9:01am.
|
|
|
|
|
How is it fixed to the top, and does it have a fixed height?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Probably easier to post _layout.cshtml
<!DOCTYPE html>
@inject IOptions<RestFactorySettings> Options;
@inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment env;
@using System.Runtime.Versioning;
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>@ViewBag.Title</title>
<link href="~/lib/bootstrap/dist/css/bootstrap.css" rel="stylesheet" />
<link href="~/css/commands.css" rel="stylesheet" />
<link href="~/css/site.css" rel="stylesheet" />
<script src="~/js/DigitalClock.js"></script>
</head>
<body>
<div class="fixed-top">
<div class="container">
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
<ul class="navbar-nav">
<li class="nav-item">
<a asp-action="GetCommands" asp-controller="Commands" class="nav-link">Commands</a>
</li>
<li class="nav-item">
<a asp-action="GetPlatforms" asp-controller="Platform" class="nav-link">Platforms</a>
</li>
<li class="nav-item">
<a asp-action="GetSiteDetails" asp-controller="Utils" class="nav-link">Site</a>
</li>
<li class="nav-item">
<a asp-action="GetActions" asp-controller="Utils" class="nav-link">Actions</a>
</li>
<li class="nav-item">
<a asp-action="GetClues" asp-controller="CCC" class="nav-link">CCC</a>
</li>
<li class="nav-item">
<a asp-action="GetSolverStats" asp-controller="CCC" class="nav-link">Solvers</a>
</li>
<li class="nav-item">
<a asp-action="GetComposerStats" asp-controller="CCC" class="nav-link">Composers</a>
</li>
<li class="nav-item">
<a asp-action="GetWord" asp-controller="RapidAPI" class="nav-link">Get Definition</a>
</li>
<li class="nav-item">
<a asp-action="GetRandomWord" asp-controller="RapidAPI" class="nav-link">Random Word</a>
</li>
</ul>
</nav>
</div>
</div>
<div class="container">
@RenderBody()
@RenderSection("OptionalStuff", false)
</div>
<br/>
</body>
</html>
"Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP
|
|
|
|
|
That makes it tricky - the fixed top navbar appears on top of the sticky table header, and doesn't have a fixed height. I suspect you'll need some Javascript to fix that:
.table-frozen thead th,
.table-frozen thead td {
position: sticky;
top: var(--content-top, 0);
background: white;
}
body {
padding-top: var(--content-top, 0);
}
const updateNavbarHeight = function(){
const navbar = document.querySelector(".fixed-top");
const top = navbar.offsetHeight;
document.documentElement.style.setProperty("--content-top", `${top}px`);
};
document.addEventListener("DOMContentLoaded", function(){
updateNavbarHeight();
const ro = new ResizeObserver(() => updateNavbarHeight());
ro.observe(document.documentElement);
}); Demo[^]
ResizeObserver - Web APIs | MDN[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Getting out of my html depth here , do I just set the class of my table to table-frozen,add the js and leave everything else as is ? thanks for your patience
"Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP
|
|
|
|
|
You'll need to add the JS and CSS, and then add the table-frozen class to your table.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hasn't made any difference Richard
"Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP
|
|
|
|
|
Works fine in the demo I posted:
Edit fiddle - JSFiddle - Code Playground[^]
Check that you included the JS and CSS correctly, and that the page isn't loading a cached version of your CSS or JS files. Also check the developer console for errors.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Working fine now Richard ( cache was the problem ) thanks very much for your help
"Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP
|
|
|
|
|
in my project i have a file upload control and then what I want know when i upload a file from that excel the first column of the excel which is employeeID give to one variable and frind the match value from database and when the required data find bind the value from database and the rest column of the excel in linq query.
please an one can help me .!
|
|
|
|
|
Based on that vague, rambling, and unclear description? No, nobody can help you.
You need to provide a clear and precise description of what you are trying to do, what you have tried, and where you are stuck. Include sample input and expected output, the relevant parts of your code, and the full details of any errors.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
What might help is for you to ask a question here using specific terms deployed in your ASP.NET code scheme. If you don't have a scheme, find one here using the search engine, crossing your fingers just before you hit the "do-the-search" button.
To get started, find terms here (for example):Two way data binding in ASP.NET[^]
Like I said "might" ... as I use that overbearing display of the word "may" here as an epexegesis.
|
|
|
|
|
I write in Postman this URL for Get method: https://localhost:7033/api/restaurant and I get 404 not found result. I don't know where is the problem. For https://localhostlocalhost:7033 it works, so it must be something wrong with [Route("api/restaurant")]
Here is the Controller code:
[Route("api/restaurant")]
public class RestaurantController : ControllerBase
{
private readonly RestaurantDbContext _dbContext;
public RestaurantController(RestaurantDbContext dbContext)
{
_dbContext = dbContext;
}
[HttpGet]
public ActionResult<ienumerable<restaurant>> GetAll()
{
var restaurants = _dbContext.Restaurants.ToList();
return Ok(restaurants);
}
}
and launchSettings file code:
}
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:8196",
"sslPort": 44311
}
},
"profiles": {
"RestaurantApp": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7033;http://localhost:5033",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
modified 6-Feb-22 6:13am.
|
|
|
|
|
|
I use repository pattern in my project. Which coding strategy is better?
1)
var messages = _messageRepository.GetAllMessages().Where(x => x.senderId == myId).ToList();
2)
var messages = _messageRepository.GetAllMessages(myId).ToList();
|
|
|
|
|
EF Core is smart enough to run the ToList after the entire SQL query has been built. I am guessing the GetAllMessages part applies the filtering to the query as well; if so, they're the same in the same query builder. You need to understand two parts here. First, EF Core builds a single query that is sent to the database engine. The fluent way to build a query helps you apply all sorts of ORDER BY s and WHERE s to the SQL query; including any JOIN s. Then, the database query planner kicks in and prepares how to capture the data. Database query plan will always try to find the optimum way to execute the SQL commands and return the results.
Since query plans are highly based on databases themselves, I would link a Wikipedia article: Query plan - Wikipedia, you can search for the documentation per your database engine.
Now, the performance would take a toll if you are filtering on the server side and not on the database side. What I mean is, that you capture the list of the records from the database and then filter them in the memory of the server process. Boy, that'd hurt a lot.
Applies to modern async-based EF-only: Finally, the performance can be improved (in terms of number of requests per second) if you would use ToListAsync() instead of ToList() , where the later is a synchronous operation and would block the thread.
DbContext Lifetime, Configuration, and Initialization - EF Core | Microsoft Docs
Efficient Querying - EF Core | Microsoft Docs
Performance Diagnosis - EF Core | Microsoft Docs
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
I'm creating a .net app in which many clients will have their own scheduled tasks. Each client will be a plugin that gets added to the main app with their own jobs and settings for when to run. What I'm looking to do is have create a job scheduler that will find all the tasks and run them based on the client settings.I'm looking at hangfire, quartz.net, and azure functions/webjobs.
Since this will be hosted on azure, I'm leaning towards an azure function that would run every minute, read a database to find each task, use reflection to find the scheduled task class since they're plugins, check the settings for how often to run the task and run it accordingly. I would just like to hear some ideas from what others have tried with success
|
|
|
|
|
To answer the question you have to assess how many users and how often these jobs are invoked. Since azure functions are billed per invocation it might be a huge cost-saver or real burden. So in case you estimate low usage I'd suggest azure functions, otherwise stick to quartz/hangfire. Tbh I've never used hangfire but quartz is a nice reliable library that allows persisting jobs in DB which is pretty convenient.
|
|
|
|
|
I am starting on a project, together with other developers. The customer is a community and wants to have a website where people can apply for a service. According to their family status, the persons are being distinguished into cases, i.e. married, divorced, living together with a partner, widow. For every case there exist some different questions, although most of them are common (like bitrhday place, father name and so on). The technology used is ASP.NET Core MVC.
The one proposition is to make a model, a controller and a view for every family status. The name of the classes should accordingly change, like MarriedModel.cs, MarriedController.cs, or DivorcedModel.cs, DivorcedController.cs etc.
My approach is a more OOP one. Since we have an entity of a Person, this is our model class. Family status, liked married, divorced etc, consists an attribute. The actions should change dynamically passing the attribute parameter into the controller which would control the view appropriate.
I find that this way we avoid redundancy and code copying, which is very bad enginnering. Moreover we have less code in the end. Others say that with the first way we would gain on flexibility in case something changes during developement.
What do you think?
|
|
|
|
|
hey every one!
i was tried to drop down with searchable way means when i try to write the first letter of the option the value should come first, with out Jquery or java script only in c# drop-down control properties.
any one please help me.
|
|
|
|