Kategorie: Allgemein

  • EntityFramework.Core in eine .net Core Blazor WebApp integrieren

    1. Install necessary packages:

    For a Blazor Server App, you’d typically manage the EF Core functionality in the Server project. So, make sure you are working in the Server project directory or set the Server project as the default project in the Package Manager Console (PMC) in Visual Studio.

    Using the NuGet Package Manager or the PMC, install the following packages:

    • Microsoft.EntityFrameworkCore
    • Microsoft.EntityFrameworkCore.SqlServer
    • Microsoft.EntityFrameworkCore.Tools (for migration tools)

    2. Define your Model:

    Create classes that will define the structure of your database tables. Place these in the Shared or Server project, depending on your design decisions.

    Example:

    public class Product
    {
        public int ProductId { get; set; }
        public string Name { get; set; }
        public decimal Price { get; set; }
    }
    

    3. Create a DbContext:

    In the Server project, create a class that derives from DbContext:

    public class AppDbContext : DbContext
    {
        public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
    
        public DbSet<Product> Products { get; set; }
    }
    

    4. Configure the Connection String:

    In the appsettings.json file in the Server project, add your connection string:

    {
      "ConnectionStrings": {
        "DefaultConnection": "Server=Servername;Database=DatabaseName;user=UserId;password=secret;MultipleActiveResultSets=true;TrustServerCertificate=True;MultiSubnetFailover=True"
      }
    }
    

    Replace YourConnectionStringHere with your MS SQL Server 2022 connection string.

    5. Register DbContext:

    In the Startup.cs (or Program.cs for newer versions) of your Server project, register the DbContext in the ConfigureServices method:

    builder.Services.AddDbContext<AppDbContext>(options =>
    options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));

    (Do not forget to import EF Core)

    6. Create Initial Migration:

    In the PMC or terminal, navigate to the Server project directory and run:

    Add-Migration InitialCreate
    

    This will scaffold a migration to create the initial set of tables for your model.

    7. Update the Database:

    Apply the migration to create the database schema:

    Update-Database
    
    
    

    8. Use the DbContext in your app:

    Now you can inject and use your DbContext in your pages, components, or services:

    csharpCopy code@inject AppDbContext _context
    
    // ...
    
    var products = await _context.Products.ToListAsync();
    

    That’s the basic setup! As your app grows, you might add more entities, relationships, migrations, and other advanced EF Core features. Ensure you understand concepts like the lifecycle of a DbContext and how it tracks changes to entities to avoid issues when manipulating data.


  • Zertifikatsanmeldung an sftp-Server

    To authenticate against an SFTP (SSH File Transfer Protocol) server using a certificate, you typically need an SSH key pair consisting of a private key and a corresponding public key. The private key remains on your local system, while the public key is uploaded to the SFTP server for authentication.

    Here’s a general outline of the process:

    1. Generate an SSH key pair: Use a tool like ssh-keygen (available on most operating systems) to generate a key pair. This command typically generates a private key file (e.g., id_rsa) and a public key file (e.g., id_rsa.pub). Example command: ssh-keygen -t rsa -b 4096
    2. Provide the public key to the SFTP server: The public key needs to be added to the server’s authorized keys file. This process depends on the specific server and its configuration. It may involve copying the public key contents into a specific file or using an administration interface to upload the key.
    3. Configure your SFTP client: In your SFTP client application (e.g., FileZilla, WinSCP, or command-line tools like sftp or scp), you’ll need to specify the private key file for authentication. The exact method of configuring this varies depending on the client you’re using.
    • In graphical SFTP clients: Look for an option to configure SSH keys or identity files. Provide the path to the private key file there.
    • In command-line clients: Use the -i flag followed by the path to the private key file. Example command: sftp -i /path/to/private_key user@server
    1. Connect to the SFTP server: With the private key configured, initiate a connection to the SFTP server using your client. It should use the private key for authentication and establish a secure connection.

    It’s worth noting that the specific steps may differ depending on the SFTP server software, client application, and operating system you’re using. It’s recommended to refer to the documentation or guides provided by your server and client for detailed instructions specific to your setup.


  • Installation .net Core 6 Webserver auf Ubuntu 20.04 LTS (Turbo-Modus)

    Vorbereitung des Servers

    WWW-User einrichten

    Das Web wird später NICHT unter Deinem Benutzer, mit dem Du gerade angemeldet bist ausgeführt und schon gar nicht unter root.

    Hierzu legen wir uns einen Benutzer an (www), der möglichste über keine Berechtigungen verfügt. Auf einem Testsystem wie demjenigen, welches wir gerade installieren verwenden wir jedoch sie sudo-Berechtigung, um uns nicht immer umloggen oder mehrere Terminalfenster mit mehreren Anmeldungen aufzuführen (würde das Tutorial erschweren).

    sudo adduser www

    Diesem ist ein vernünftiges (da es sich durch das Web später um einen sehr exponierten Benutzer handelt: SEHR vernünftiges) Passwort zu vergeben und der Rest kann ausgefüllt oder leer gelassen werden:

    Jetzt (wie gesagt nur in der Testumgebung) den neuen User mit sudo-Rechten versehen:

    sudo usermod -aG sudo www

    (todo) Firewall installieren

    Installation nginx

    Quelle: https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-20-04-de

    Nun auf den neun angelegten Benutzer www umloggen (dann wird das Standard-Web auch schon mit diesem Benutzer angelegt).

    su - www

    Nun nginx installieren

    sudo apt install nginx

    (todo) Firewall anpassen

    Installation AspDotNetCore

    Wie immer zuerst den Server aktualisieren

    sudo apt update
    sudo apt upgrade

    Basierend auf dieser Quelle: https://docs.microsoft.com/en-us/dotnet/core/install/linux-ubuntu

    Zuerst die Microsoft-Paketlisten dem System hinzufügen

    wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
    sudo dpkg -i packages-microsoft-prod.deb
    rm packages-microsoft-prod.deb

    Dann die apsnetcore Runtime imstallieren

    sudo apt-get install -y apt-transport-https
    sudo apt-get update
    sudo apt-get install -y aspnetcore-runtime-6.0


  • Shadowlands Erze

    ErzBastionMaldraxxusArdenwaldRevendreth
    LaestritXXXX
    ElethiumXXXX
    SoleniumX
    OxxeinX
    PhaedrumX
    SinvyrX

Wir benutzen Cookies um die Nutzerfreundlichkeit der Webseite zu verbessen. Durch Deinen Besuch stimmst Du dem zu.