AK sanTari
AK sanTari
CC#
Created by AK sanTari on 3/21/2024 in #help
.NET 7 Blazor - add XSS policy
hi all, what is the best way aviod XSS attacks in a .net 7 blazor app? (my main goal is to prevent users to input scripts (eg. <script>alert('foo');</script>) in any of the text boxes in my app. For more context i m using web assembly and building the app with WebAssemblyHostBuilder
1 replies
CC#
Created by AK sanTari on 11/6/2023 in #help
✅ Grister.js - alternate row colour
No description
4 replies
CC#
Created by AK sanTari on 10/25/2023 in #help
❔ MvvmCross - MvxRecyclerView GetChildAt(position) returns null
i have a problem where GetChildAt returns null for all elements out of view ( i have a MvxRecyclerView with many elements and they don't all fit in the screen - have a scroll component) GetChildAt work only on all elements that are visible (fit in the screen) when i click a certain button. There are solution for java/javascript apps but they don't work with xamarin. Anybody has any idea how to make it work?
c#
[Activity()]
public class MyView : MvxActivity<MyViewModel>
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
///...some code
Button btnSave = FindViewById<Button>(Resource.Id.SaveButton);
btnSave.Click += async delegate {
var signatoryList = FindViewById<MvxRecyclerView>(Resource.Id.signatoryList);

int position = 0;
bool signaturesSaved = false;

foreach (Signatory signatory in signatoryList.ItemsSource)
{
try
{
RecyclerView.ViewHolder holder = signatoryList.FindViewHolderForItemId(Resource.Id.signatoryList);
View signatoryView = signatoryList.GetChildAt(position);
signaturePad = signatoryView.FindViewById<SignaturePadView>(Resource.Id.signatureImage);

///... save the signature byte array

c#
[Activity()]
public class MyView : MvxActivity<MyViewModel>
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
///...some code
Button btnSave = FindViewById<Button>(Resource.Id.SaveButton);
btnSave.Click += async delegate {
var signatoryList = FindViewById<MvxRecyclerView>(Resource.Id.signatoryList);

int position = 0;
bool signaturesSaved = false;

foreach (Signatory signatory in signatoryList.ItemsSource)
{
try
{
RecyclerView.ViewHolder holder = signatoryList.FindViewHolderForItemId(Resource.Id.signatoryList);
View signatoryView = signatoryList.GetChildAt(position);
signaturePad = signatoryView.FindViewById<SignaturePadView>(Resource.Id.signatureImage);

///... save the signature byte array

2 replies
CC#
Created by AK sanTari on 9/1/2022 in #help
Dapper map to multiple Dictionaries
I'm using Dapper and .NET core 6 and am trying to map an object with multiple dictionaries in one sql query... is it possible? The object looks like the following:
public class MasterDataModel
{
public IEnumerable<KeyValuePair<int, string>>? Titles { get; set; }
public IEnumerable<KeyValuePair<int, string>>? Genders { get; set; }
public IEnumerable<KeyValuePair<int, string>>? Countries { get; set; }
}
public class MasterDataModel
{
public IEnumerable<KeyValuePair<int, string>>? Titles { get; set; }
public IEnumerable<KeyValuePair<int, string>>? Genders { get; set; }
public IEnumerable<KeyValuePair<int, string>>? Countries { get; set; }
}
I can easily make multiple calls and map them (as follow) but was looking for something nicer.
var titles = await Task.FromResult(ExecuteQuery(q => q.Query<dynamic>("SELECT * FROM Mst.Title"))
.ToDictionary(r => (int)r.TitleID, r => (string)r.TitleValue));

return new MasterDataModel() { Titles = titles };
var titles = await Task.FromResult(ExecuteQuery(q => q.Query<dynamic>("SELECT * FROM Mst.Title"))
.ToDictionary(r => (int)r.TitleID, r => (string)r.TitleValue));

return new MasterDataModel() { Titles = titles };
Being using Slapper for other repo calls but can't find online anything for Dictionaries. Any idea? Or can a stored procedure do that and Dapper detect and map the object?
1 replies
CC#
Created by AK sanTari on 8/22/2022 in #help
.NET CORE 6 - Injecting IDbConnection... is it good practice?
I have an api to build and using dapper - IDbConnection. Atm i have an instance of IDbConnection for every db call and i dispose it immediately:
public async Task<IEnumerable<T>> LoadData<T>(
string sqlQuery,
string connectionId)
{
using IDbConnection dbConnection = new SqlConnection(_configuration.GetConnectionString(connectionId));

return await dbConnection.QueryAsync<T>(sqlQuery);
}
public async Task<IEnumerable<T>> LoadData<T>(
string sqlQuery,
string connectionId)
{
using IDbConnection dbConnection = new SqlConnection(_configuration.GetConnectionString(connectionId));

return await dbConnection.QueryAsync<T>(sqlQuery);
}
Since i only have one sql database to query, is it good practice to inject the dbConnection on startup? Will this cause any performance issue since the connection will stay open all the time (if i'm correct)?
5 replies