Gipper
Gipper
CC#
Created by Gipper on 6/5/2024 in #help
Easiest and simplest way to insert a Microsoft SQL Server DB into an app saving data in csv files?
I got a solution with several projects, most of them are console applications, one is a gRPC server. I'm currently saving data in a sequence of csv files and I would like to do the same in a simple database with as many tables as I have csv files (about 6/7 of them). What would be the best way to inject a database in it? I say MSSQL Server only because that's the one I got setup on my system, could be another one hypothetically. So long as it's quick and easy πŸ™‚
20 replies
CC#
Created by Gipper on 4/26/2024 in #help
Can I set up an integration testing environment with no app available and no code? If so, how?
Right now I have a test solution set up for ASP.NET and I can't launch it because it says WebServer failed to listen on port port_number. I am trying to use XUnit now:
public class TestesIntegracaoUser : IClassFixture<WebApplicationFactory<Program>>
{
private readonly WebApplicationFactory<Program> _factory;
private const string URLBase = "http://User";

public TestesIntegracaoUser(WebApplicationFactory<Program> factory)
{
_factory = factory;
}
//Actual test code
}
public class TestesIntegracaoUser : IClassFixture<WebApplicationFactory<Program>>
{
private readonly WebApplicationFactory<Program> _factory;
private const string URLBase = "http://User";

public TestesIntegracaoUser(WebApplicationFactory<Program> factory)
{
_factory = factory;
}
//Actual test code
}
I thought that WebApplicationFactory should have generated a web server for testing, but it's not doing so. I need it so I can debug this code, if I can.
78 replies
CC#
Created by Gipper on 4/24/2024 in #help
βœ… Please help me read this simple API endpoint documentation
No description
51 replies
CC#
Created by Gipper on 4/16/2024 in #help
Help implementing multithreading in a distributed system, please?
I got a distributed system, meaning one solution that's a server and two which are clients. The objective is to use threads so that more than one client can communicate over TCP with the server simultaneously. I was told that I need to make it so there is some kind of code that makes it so different clients connect through different ports or the communication won't go well, but I really don't know. Any help you can give me? I know this isn't much to go on, but I'm trying to figure it out myself and feel free to ask questions and I'll do my best to answer.
53 replies
CC#
Created by Gipper on 4/10/2024 in #help
Help me sort out perhaps badly done folder/solution structure so I can add a shared Class Library
Ok, so I have two solutions which must be separate so I can execute them both at the same time so they will communicate (it includes TCP communication between them). They are both inside their own folder (called "Servidor" and "Cliente1") and both these folders are in turn inside a unifying folder called "TP1Code". Here's the output for the root folder of this project from the command line which may be enlightening (truncated for simplicity):
C:.
β”œβ”€β”€β”€.vs
β”‚ └───TP1
β”œβ”€β”€β”€CommonLibrary
β”‚ β”œβ”€β”€β”€bin
β”‚ β”‚ β”œβ”€β”€β”€Debug
β”‚ β”‚ β”‚ └───net8.0
β”‚ β”‚ └───Release
β”‚ β”‚ └───net8.0
β”‚ └───obj
β”‚ β”œβ”€β”€β”€Debug
β”‚ β”‚ └───net8.0
β”‚ β”‚ β”œβ”€β”€β”€ref
β”‚ β”‚ └───refint
β”‚ └───Release
β”‚ └───net8.0
β”‚ β”œβ”€β”€β”€ref
β”‚ └───refint
└───TP1Code
β”œβ”€β”€β”€.github
β”‚ └───workflows
β”œβ”€β”€β”€bin
β”‚ β”œβ”€β”€β”€Debug
β”‚ β”‚ └───net8.0
β”‚ └───Release
β”‚ └───net8.0
β”œβ”€β”€β”€Cliente1
β”‚ β”œβ”€β”€β”€bin
β”‚ β”‚ β”œβ”€β”€β”€Debug
β”‚ β”‚ β”‚ └───net8.0
β”‚ β”‚ └───Release
β”‚ β”‚ └───net8.0
β”‚ └───obj
β”‚ β”œβ”€β”€β”€Debug
β”‚ β”‚ └───net8.0
β”‚ β”‚ β”œβ”€β”€β”€ref
β”‚ β”‚ └───refint
β”‚ └───Release
β”‚ └───net8.0
β”‚ β”œβ”€β”€β”€ref
β”‚ └───refint
└───Servidor
β”œβ”€β”€β”€bin
β”‚ β”œβ”€β”€β”€Debug
β”‚ β”‚ └───net8.0
β”‚ └───Release
β”‚ └───net8.0
β”œβ”€β”€β”€Files
β”œβ”€β”€β”€obj
β”‚ β”œβ”€β”€β”€Debug
β”‚ β”‚ └───net8.0
β”‚ β”‚ β”œβ”€β”€β”€ref
β”‚ β”‚ └───refint
β”‚ └───Release
β”‚ └───net8.0
β”‚ β”œβ”€β”€β”€ref
β”‚ └───refint
└───Properties
└───PublishProfiles
C:.
β”œβ”€β”€β”€.vs
β”‚ └───TP1
β”œβ”€β”€β”€CommonLibrary
β”‚ β”œβ”€β”€β”€bin
β”‚ β”‚ β”œβ”€β”€β”€Debug
β”‚ β”‚ β”‚ └───net8.0
β”‚ β”‚ └───Release
β”‚ β”‚ └───net8.0
β”‚ └───obj
β”‚ β”œβ”€β”€β”€Debug
β”‚ β”‚ └───net8.0
β”‚ β”‚ β”œβ”€β”€β”€ref
β”‚ β”‚ └───refint
β”‚ └───Release
β”‚ └───net8.0
β”‚ β”œβ”€β”€β”€ref
β”‚ └───refint
└───TP1Code
β”œβ”€β”€β”€.github
β”‚ └───workflows
β”œβ”€β”€β”€bin
β”‚ β”œβ”€β”€β”€Debug
β”‚ β”‚ └───net8.0
β”‚ └───Release
β”‚ └───net8.0
β”œβ”€β”€β”€Cliente1
β”‚ β”œβ”€β”€β”€bin
β”‚ β”‚ β”œβ”€β”€β”€Debug
β”‚ β”‚ β”‚ └───net8.0
β”‚ β”‚ └───Release
β”‚ β”‚ └───net8.0
β”‚ └───obj
β”‚ β”œβ”€β”€β”€Debug
β”‚ β”‚ └───net8.0
β”‚ β”‚ β”œβ”€β”€β”€ref
β”‚ β”‚ └───refint
β”‚ └───Release
β”‚ └───net8.0
β”‚ β”œβ”€β”€β”€ref
β”‚ └───refint
└───Servidor
β”œβ”€β”€β”€bin
β”‚ β”œβ”€β”€β”€Debug
β”‚ β”‚ └───net8.0
β”‚ └───Release
β”‚ └───net8.0
β”œβ”€β”€β”€Files
β”œβ”€β”€β”€obj
β”‚ β”œβ”€β”€β”€Debug
β”‚ β”‚ └───net8.0
β”‚ β”‚ β”œβ”€β”€β”€ref
β”‚ β”‚ └───refint
β”‚ └───Release
β”‚ └───net8.0
β”‚ β”œβ”€β”€β”€ref
β”‚ └───refint
└───Properties
└───PublishProfiles
The important folders here are TP1Code itself, Servidor and Cliente1. What I want to do is add some code (only methods really) which is viewed and usable from within Servidor and Cliente1. Perhaps in the form of a Class Library?? Help?
60 replies
CC#
Created by Gipper on 4/3/2024 in #help
How to find relative file path for file inside of project?
Dealing with a C# console application, I have a folder inside the project named Files and inside that folder I have a file Servicos_A.csv. I want to get a relative path to that file for File I/O. My concern with using absolute path is that when I push it to github it won't work in my colleague's computer cause obviously his filesystem will be different from mine. How can I get to that path? I already searched it and asked generative AIs but it won't work, mostly because using the string assemblyDirectory = AppDomain.CurrentDomain.BaseDirectory utility for a part of the path seems to add some unnecessary and non-existing directories into the path for some reason.
2 replies
CC#
Created by Gipper on 3/5/2024 in #help
Advice on how to correctly integrate more complex Javascript code
Hey, I've developed an ASP.NET app before, but that one was pretty much all about the backend and the database. This next one I'm about to begin on will be almost the opposite, with much more complex frontend, particularly when it comes to Javascript code. Any advice on how to do it differently so to integrate everything properly and avoiding mistakes?
6 replies
CC#
Created by Gipper on 2/15/2024 in #help
Best way to do this OOP-wise???
Ok, so this is not the actual program but for the sake of brevity I'll give you an equivalent one:
namespace namespace1
{
internal class Program
{

static void Main(string[] args)
{
BaseClass baseClass = new BaseClass();
DerivedClass1 = new DerivedClass1();//Here I initialize fields in BaseClass
DerivedClass2 = new DerivedClass2();//Here I want the data initialized in BaseClass on the previous line
}
}
}
namespace namespace1
{
internal class Program
{

static void Main(string[] args)
{
BaseClass baseClass = new BaseClass();
DerivedClass1 = new DerivedClass1();//Here I initialize fields in BaseClass
DerivedClass2 = new DerivedClass2();//Here I want the data initialized in BaseClass on the previous line
}
}
}
internal class BaseClass
{
private protected int someData;
private protected string someMoreDataStr;
}
internal class BaseClass
{
private protected int someData;
private protected string someMoreDataStr;
}
internal class DerivedClass1 : BaseClass
{
\\THIS CLASS INITIALIZES DATA TO THE FIELDS IN BASECLASS
public DerivedClass1()
{
someData=3;
someMoreDataStr = "foo";
}
}
internal class DerivedClass1 : BaseClass
{
\\THIS CLASS INITIALIZES DATA TO THE FIELDS IN BASECLASS
public DerivedClass1()
{
someData=3;
someMoreDataStr = "foo";
}
}
internal class DerivedClass2 : BaseClass
{
\\This Class will be instantiated after DerivedClass1 And I want to have the 3 And the "foo" In there
public DerivedClass2()
{
\\I want to have the same data initialized earlier here
}
}
internal class DerivedClass2 : BaseClass
{
\\This Class will be instantiated after DerivedClass1 And I want to have the 3 And the "foo" In there
public DerivedClass2()
{
\\I want to have the same data initialized earlier here
}
}
Right now what I'm doing is:
namespace namespace1
{
internal class Program
{

static void Main(string[] args)
{
BaseClass baseClass = new BaseClass();
DerivedClass1 = new DerivedClass1(baseClass);//Here I initialize fields in BaseClass
DerivedClass2 = new DerivedClass2(baseClass);//Here I want the data initialized in BaseClass on the previous line
}
}
}
namespace namespace1
{
internal class Program
{

static void Main(string[] args)
{
BaseClass baseClass = new BaseClass();
DerivedClass1 = new DerivedClass1(baseClass);//Here I initialize fields in BaseClass
DerivedClass2 = new DerivedClass2(baseClass);//Here I want the data initialized in BaseClass on the previous line
}
}
}
and just accessing the data through the argument passed in to the constructor and I'm only inheriting so I can access the private protected field in BaseClass. Is there a better way of doing this (i.e. two classes derived from the same base sharing the values of the vars in the baseObj)? Should I just make the field public and not inherit?
24 replies
CC#
Created by Gipper on 1/31/2024 in #help
How to pass variable from one View to another View in link?
Ok, so I have this code in my view:
@foreach (var item in Model)
{
@if(Model.Any(utilizadorGrupo=>utilizadorGrupo.UtilizadorId == userID))
{
@if (userID == item.UtilizadorId)
{

<a id="nomeGrupo" href="@Url.Action("verPublicacaoGrupo")?nomeGrupo=@item.Grupo.Nome_grupo"><strong>@item.Grupo.Nome_grupo</strong></a>
}
}
}
@foreach (var item in Model)
{
@if(Model.Any(utilizadorGrupo=>utilizadorGrupo.UtilizadorId == userID))
{
@if (userID == item.UtilizadorId)
{

<a id="nomeGrupo" href="@Url.Action("verPublicacaoGrupo")?nomeGrupo=@item.Grupo.Nome_grupo"><strong>@item.Grupo.Nome_grupo</strong></a>
}
}
}
as you can see, in this view I am including a link to another view, I loop through a collection of objects and would like to pass the value of one of the fields of that object (Nome_grupo) to the view being linked to. I am doing it in the Razor syntax way because it seemed simpler, but I am open to any other way as this one has proved a bit wonky.
26 replies
CC#
Created by Gipper on 1/29/2024 in #help
How to use UserManager in my controller?
What the title says, what I'm doing currently:
private SignInManager<IdentityUser> _signInManager;
private UserManager<IdentityUser> _userManager;

public UtilizadoresController(ApplicationDbContext context, SignInManager<IdentityUser> signInManager, UserManager<IdentityUser> userManager)
{
_context = context;
_signInManager = signInManager;
_userManager = userManager;
}
private SignInManager<IdentityUser> _signInManager;
private UserManager<IdentityUser> _userManager;

public UtilizadoresController(ApplicationDbContext context, SignInManager<IdentityUser> signInManager, UserManager<IdentityUser> userManager)
{
_context = context;
_signInManager = signInManager;
_userManager = userManager;
}
But Visual Studio doesn't recognize the UserManager<IdentityUser> type: 'UserManager<>' is an ambiguous reference between 'Microsoft.AspNet.Identity.UserManager<TUser>' and 'Microsoft.AspNetCore.Identity.UserManager<TUser>' When I change it to private Microsoft.AspNet.Identity.UserManager<IdentityUser> _userManager; I get this error: 'Microsoft.AspNetCore.Identity.IdentityUser' cannot be used as type parameter 'TUser' in the generic type or method 'UserManager<TUser>'. There is no implicit reference conversion from 'Microsoft.AspNetCore.Identity.IdentityUser' to 'Microsoft.AspNet.Identity.IUser<string>'.
27 replies
CC#
Created by Gipper on 1/29/2024 in #help
How do I take text from input element of a form and put it in AspNetUsers table properly?
I'm passing it from view to controller action through parameters, if that's relevant. This input element has to have the attribute type="password" btw (it is a password) and I would like to be able to hash the text input in it like the system does and put it into AspNetUsers and also take what's already there and unhash it. I'm doing this cause I want to give the user a way to change their current password to a new one, if there is a better way I'm open to suggestions.
13 replies
CC#
Created by Gipper on 1/28/2024 in #help
βœ… Changed something manually in AspNetUsers and now can't login
I went in with SQL Server Object Explorer and manually changed the NormalizedUserName column and now I can't login. I think that funked something up. What should I do?
22 replies
CC#
Created by Gipper on 1/22/2024 in #help
In an ASP.NET application, what is the way to in the view to check if user authenticated and roles?
I mean assuming you are using Asp.NET Identity resources and you have already scaffolded identity. Is it through HTTPContext? I know how to do it with [Authorize] in the controller, but that would require creating separate views for authenticated and non-authenticated viewers right? Is there an easier way through something like:
@if(check_if_authenticated)
{
//do stuff
}
@if(check_if_authenticated)
{
//do stuff
}
8 replies
CC#
Created by Gipper on 1/7/2024 in #help
ASP.NET How to create button to view under another controller?
What the title says. From a view under the Publicacoes controller I want to call another view under the Grupos controller. Currently I have this:
<a href="@Url.Action("Create", "GrupoController")">Criar grupo</a>
<a href="@Url.Action("Create", "GrupoController")">Criar grupo</a>
But it still says page can't be found. I have also tried:
<a href="@Url.Action("Create", "Grupo")">Criar grupo</a>
<a href="@Url.Action("Create", "Grupo")">Criar grupo</a>
Also, to no effect. Help?
10 replies
CC#
Created by Gipper on 1/6/2024 in #help
βœ… I can't do migrations now...
when I do add-migration nullableForeignsOnPublicacao I get:
PM> add-migration nullableForeignsOnPublicacao
Both Entity Framework 6 and Entity Framework Core are installed. The Entity Framework 6 tools are running. Use 'EntityFrameworkCore\Add-Migration' for Entity Framework Core.
A version of Entity Framework older than 6.3 is also installed. The newer tools are running. Use 'EntityFramework\Add-Migration' for the older version.
No migrations configuration type was found in the assembly 'Trabalho Lab Aplicaçáes Web'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration).
PM> add-migration nullableForeignsOnPublicacao
Both Entity Framework 6 and Entity Framework Core are installed. The Entity Framework 6 tools are running. Use 'EntityFrameworkCore\Add-Migration' for Entity Framework Core.
A version of Entity Framework older than 6.3 is also installed. The newer tools are running. Use 'EntityFramework\Add-Migration' for the older version.
No migrations configuration type was found in the assembly 'Trabalho Lab Aplicaçáes Web'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration).
So I tried Enable-Migrations, right? I got:
PM> Enable-Migrations
Both Entity Framework 6 and Entity Framework Core are installed. The Entity Framework 6 tools are running. Use 'EntityFrameworkCore\Enable-Migrations' for Entity Framework Core.
A version of Entity Framework older than 6.3 is also installed. The newer tools are running. Use 'EntityFramework\Enable-Migrations' for the older version.
No context type was found in the assembly 'Trabalho Lab Aplicaçáes Web'.
PM> Enable-Migrations
Both Entity Framework 6 and Entity Framework Core are installed. The Entity Framework 6 tools are running. Use 'EntityFrameworkCore\Enable-Migrations' for Entity Framework Core.
A version of Entity Framework older than 6.3 is also installed. The newer tools are running. Use 'EntityFramework\Enable-Migrations' for the older version.
No context type was found in the assembly 'Trabalho Lab Aplicaçáes Web'.
Which I partially understand cause it wants a class inherint fro DbContext, but my context inherits from IdentityDbContext. What should I do?
11 replies
CC#
Created by Gipper on 1/4/2024 in #help
Big problem transfering ASP.NET app from one environment to another
What the title says, I have a desktop computer at home where I do most of my development work and I built an ASP.NET app with EntityFramework and MSSQLServer. In that computer it works fine, problem is I now need to get the app to my laptop and make it work but I'm getting all kinds of problems. I'm pretty sure there's an inconsistency or several between the two databases (the one at home and the one in the laptop). But now when I do update-database it doesn't go through because either I get the error message of EFCore version being wrong or because the project can't build (but the project can't build because I can't apply the migrations and update the database). I'm pretty sure the code itself is exactly equal as I pushed it to github from home and now pulled it down on the laptop. What should I do?
86 replies
CC#
Created by Gipper on 1/3/2024 in #help
Edit view not editing the Db entry but instead creating new one
What the title says, when I hit the submit button on the Edit view of my Utilizador model class, it goes to the HTTPPost Edit method in the controller and triggers these lines:
//string aspNetUserId = User.FindFirstValue(ClaimTypes.NameIdentifier);
//string? aspNetUserEmail = _context.Users.Single(user => user.Id == aspNetUserId).Email;
//userPretendidoId = _context.Utilizadores.First(_utilizador => _utilizador.Email == aspNetUserEmail).UtilizadorId;
//utilizador = _context.Utilizadores.First(user=>user.UtilizadorId == userPretendidoId);
_context.Update(utilizador);
await _context.SaveChangesAsync();
//string aspNetUserId = User.FindFirstValue(ClaimTypes.NameIdentifier);
//string? aspNetUserEmail = _context.Users.Single(user => user.Id == aspNetUserId).Email;
//userPretendidoId = _context.Utilizadores.First(_utilizador => _utilizador.Email == aspNetUserEmail).UtilizadorId;
//utilizador = _context.Utilizadores.First(user=>user.UtilizadorId == userPretendidoId);
_context.Update(utilizador);
await _context.SaveChangesAsync();
And instead of updating the relevant table row, it simply creates and inserts a new one with the new UserName I passed in through the view. The commented out code was something I added to try and force it to be the utilizador object I want it to be (for when the update method is called), but when I uncomment and use the code it simply does not add anything.
26 replies
CC#
Created by Gipper on 1/1/2024 in #help
ASP.NET Identity need help getting to respective logged in user's row in AspNetUsers table
Hello all, What the title says, I need to know how to get to that row. Here's what I've tried already from the internet:
string aspNetUserId = System.Security.Principal.WindowsIdentity.GetCurrent().GetUserId(); //returns nothing (null)
string aspNetUserId = System.Security.Principal.WindowsIdentity.GetCurrent().GetUserId(); //returns nothing (null)
var userManager = HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>(); //doesn't know what OwinContext is and idk how to get to it + it doesn't know how to get to ApplicationUserManager and I also don't know where (if it even exists) that class is
var userManager = HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>(); //doesn't know what OwinContext is and idk how to get to it + it doesn't know how to get to ApplicationUserManager and I also don't know where (if it even exists) that class is
Help?
15 replies
CC#
Created by Gipper on 12/31/2023 in #help
How to assign roles to already created Users in ASP.NET Identity?
In ASP.NET I am trying to attribute Roles to specific users in my Database, I already have the users and the roles created in the AspNetUsers and AspNetRoles, but now I would like to attribute each to the other as I wish. Is it "safe" to do so manually, through the SQL Server Object Explorer? Will that work with the Authorize DataAnnotations later? If not what should I do?
20 replies
CC#
Created by Gipper on 12/31/2023 in #help
ASP.NET Problem with emailSender in Register Page
Hi, so I did something and now when I go to my Register page (that I got when I create the project with the "Individual Accounts" authentication option), I get this exception: InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UI.Services.IEmailSender' while attempting to activate 'Proj_Name.Areas.Identity.Pages.Account.RegisterModel'. I've tried to try to comment ou any reference to emailSender in the entire solution, doing .AddDefaultUI() in my services config, here is that config code btw:
builder.Services.AddIdentity<IdentityUser, IdentityRole>
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddRoles<IdentityRole>()
.AddDefaultTokenProviders()
.AddDefaultUI();
builder.Services.AddIdentity<IdentityUser, IdentityRole>
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddRoles<IdentityRole>()
.AddDefaultTokenProviders()
.AddDefaultUI();
I should say that I don't have an actual emailSender implement nor desire or resources to implement it. I don't actually need to have email confirmation of accounts, I was happy with what it did before which was just show the text page pretending there was an email confirmation feature when there wasn't.
14 replies