working on it ...

Filters

Explore Public Snippets

Sort by

Found 98 snippets matching: asp.net-core

    external by Temi Lajumoke  13  0  1  0

    ASP.NET-core-role-based-authentication user setup in appsettings.json file

    ASP.NET-core-role-based-authentication user setup in appsettings.json file: appsettings.json
    {
      "ConnectionStrings": {
        "DefaultConnection": "Data Source=WebApplication.db"
      },
      "AppSettings":{
        "UserEmail": "johndoe@email.com",
        "UserPassword": "P@ssw0rd"
      }
    }
    
    

    external by Ibrahim Šuta  8  0  1  0

    ASP.NET Core SignalR chat with Angular 5 - https://codingblast.com/asp-net-core-signalr-chat-angular

    ASP.NET Core SignalR chat with Angular 5 - https://codingblast.com/asp-net-core-signalr-chat-angular: Startup.cs
    app.UseCors("CorsPolicy");
    
    

    external by Ross Merrigan  4300  34  3  0

    A gzip, deflate compression middleware for vNext, ASP.NET Core

    A gzip, deflate compression middleware for vNext, ASP.NET Core: CompressionMiddleware.cs
    public class CompressionMiddleware
    {
        private readonly RequestDelegate _next;
    
        public CompressionMiddleware(RequestDelegate next)
        {
            _next = next;
        }
    
        public async Task Invoke(HttpContext context)
        {
            if (IsGZipSupported(context))
            {
                string acceptEncoding = context.Request.Headers["Accept-Encoding"];
    
                var buffer = new MemoryStream();
                var stream = context.Response.Body;
                context.Response.Body = buffer;
                await _next(context);
    
                if (acceptEncoding.Contains("gzip"))
                {
                    var gstream = new GZipStream(stream, CompressionLevel.Optimal);
                    context.Response.Headers.Add("Content-Encoding", new[] {"gzip"});
                    buffer.Seek(0, SeekOrigin.Begin);
                    await buffer.CopyToAsync(gstream);
                    gstream.Dispose();
                }
                else
                {
                    var gstream = new DeflateStream(stream, CompressionLevel.Optimal);
                    context.Response.Headers.Add("Content-Encoding", new[] { "deflate" });
                    buffer.Seek(0, SeekOrigin.Begin);
                    await buffer.CopyToAsync(gstream);
                    gstream.Dispose();
                }
            }
            else
            {
                await _next(context);
            }
        }
    
        public bool IsGZipSupported(HttpContext context)
        {
            string acceptEncoding = context.Request.Headers["Accept-Encoding"];
            return !string.IsNullOrEmpty(acceptEncoding) &&
                   (acceptEncoding.Contains("gzip") || acceptEncoding.Contains("deflate"));
        }
    }
    
    
    
    

    external by flagshipxyz  57  0  1  0

    asp.net core:データベース接続先の設定

    asp.net core:データベース接続先の設定: Startup.cs
    public void ConfigureServices(IServiceCollection services)
    {
        // Add framework services.
        services.AddDbContext<ApplicationDbContext>(options =>
            options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection")));
        //services.AddDbContext<ApplicationDbContext>(options =>
        //    options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
    
        services.AddIdentity<ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores<ApplicationDbContext>()
            .AddDefaultTokenProviders();
    
        services.AddMvc();
    
        // Add application services.
        services.AddTransient<IEmailSender, AuthMessageSender>();
        services.AddTransient<ISmsSender, AuthMessageSender>();
    }
    
    
    

    external by matjazmav  57  0  1  0

    ASP.NET Core Workshop

    ASP.NET Core Workshop: install.sh
    # curl -sL $url | sudo bash -
    
    # 1) Add the dotnet apt-get feed & Install .NET Core SDK (https://www.microsoft.com/net/core)
    echo "Installing .NET Core SDK ..."
    sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ xenial main" > /etc/apt/sources.list.d/dotnetdev.list'
    apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 417A0893
    apt-get update
    apt-get -y install dotnet-dev-1.0.0-preview2.1-003177
    
    # 3) Install git (https://git-scm.com/)
    echo "Installing git ..."
    apt-get -y install git
    
    # 4) Install node (https://nodejs.org/en/)
    echo "Installing node ..."
    curl -sL https://deb.nodesource.com/setup_6.x | bash -
    apt-get -y install -y nodejs
    
    # 5) Install Visual Studio Code (https://code.visualstudio.com/)
    echo "Installing Visual Studio Code ..."
    wget -O vscode.deb "https://go.microsoft.com/fwlink/?LinkID=760868"
    dpkg -i vscode.deb
    rm -f vscode.deb
    
    # 6) Install Yeoman (http://yeoman.io/), Bower (https://bower.io/) & ASP.NET Generator (https://github.com/omnisharp/generator-aspnet)
    echo "Installing Yeoman, Bower & ASP.NET Generator ..."
    npm install -g yo bower generator-aspnet
    
    echo "DONE"
    
    

    external by Bernard Anderson  45  0  1  0

    Steps for Building ASP.NET Core webapi with a single view (in Linux)

    Steps for Building ASP.NET Core webapi with a single view (in Linux): gistfile1.txt
    (Assuming you've already installed Linux, .NET Core)
    
    Follow the steps to install Yeoman.  Yeoman adds additional options to build a DOTNET Core app without extra, unneeded stuff:
      https://docs.microsoft.com/en-us/aspnet/core/client-side/yeoman
    
    After installation, run Yeoman in the base directory you want the new project to be created: 
      > yo aspnet
      
    The webapi option gives to the most basic web app with no views. To add a view, follow the steps to add a view controller and view:
      https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/adding-controller
      https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/adding-view
      Don't forget to add this code in the Startup.cs > public void Configure method:
          app.UseMvc(routes =>
          {
            routes.MapRoute(
              name: "default",
              template: "{controller=Home}/{action=Index}/{id?}");
          });
          
    Checkout this link on how to set up additional routes:
      https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/routing
          
          
          
    
    

    external by ArtifexPaul  34  0  1  0

    NPOCO - Address Class for ASP.NET Core 1

    NPOCO - Address Class for ASP.NET Core 1: Address.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using NPoco;
    
    namespace NPOCOTestProject.Models
    {
        [TableName("ADDR_Address")]
        [PrimaryKey("ADDR_ID")]
        public class Address
        {
            public int ADDR_ID { get; set; }
            public int ADDR_FK_USER_ID { get; set; }
            public string ADDR_AddressType { get; set; }
            public string ADDR_StreetAddress { get; set; }
            public string ADDR_City { get; set; }
            public Int16 ADDR_FK_STTE_ID { get; set; }
            public string ADDR_PostalCode { get; set; }
    
            [Ignore]
            internal bool IsNew
            {
                get
                {
                    return this.ADDR_ID == default(int);
                }
            }
    
            [Ignore]
            public bool IsDeleted { get; set; }
        }
    }
    
    
    

    external by Ross Merrigan  2220  4  3  0

    CompressionMiddleware for MVC vNext, ASP.NET Core supports gzip and deflate

    CompressionMiddleware for MVC vNext, ASP.NET Core supports gzip and deflate: CompressionMiddleware.cs
    public class CompressionMiddleware
    {
        private readonly RequestDelegate _next;
    
        public CompressionMiddleware(RequestDelegate next)
        {
            _next = next;
        }
    
        public async Task Invoke(HttpContext context)
        {
            if (IsGZipSupported(context))
            {
                string acceptEncoding = context.Request.Headers["Accept-Encoding"];
    
                var buffer = new MemoryStream();
                var stream = context.Response.Body;
                context.Response.Body = buffer;
                await _next(context);
    
                if (acceptEncoding.Contains("gzip"))
                {
                    var gstream = new GZipStream(stream, CompressionLevel.Optimal);
                    context.Response.Headers.Add("Content-Encoding", new[] {"gzip"});
                    buffer.Seek(0, SeekOrigin.Begin);
                    await buffer.CopyToAsync(gstream);
                    gstream.Dispose();
                }
                else
                {
                    var dstream = new DeflateStream(stream, CompressionLevel.Optimal);
                    context.Response.Headers.Add("Content-Encoding", new[] { "deflate" });
                    buffer.Seek(0, SeekOrigin.Begin);
                    await buffer.CopyToAsync(dstream);
                    dstream.Dispose();
                }
            }
            else
            {
                await _next(context);
            }
        }
    
        public bool IsGZipSupported(HttpContext context)
        {
            string acceptEncoding = context.Request.Headers["Accept-Encoding"];
            return !string.IsNullOrEmpty(acceptEncoding) &&
                   (acceptEncoding.Contains("gzip") || acceptEncoding.Contains("deflate"));
        }
    }
    
    
    
    

    external by Ricardo Biruel  23  0  1  0

    My .gitignore for Visual Studio (ASP.NET Core)

    My .gitignore for Visual Studio (ASP.NET Core): .gitignore
    # Created by https://www.gitignore.io/api/visualstudio
    
    ### VisualStudio ###
    ## Ignore Visual Studio temporary files, build results, and
    ## files generated by popular Visual Studio add-ons.
    
    # User-specific files
    *.suo
    *.user
    *.userosscache
    *.sln.docstates
    
    # User-specific files (MonoDevelop/Xamarin Studio)
    *.userprefs
    
    # Build results
    [Dd]ebug/
    [Dd]ebugPublic/
    [Rr]elease/
    [Rr]eleases/
    x64/
    x86/
    bld/
    [Bb]in/
    [Oo]bj/
    [Ll]og/
    
    # Visual Studio 2015 cache/options directory
    .vs/
    # Uncomment if you have tasks that create the project's static files in wwwroot
    #wwwroot/
    
    # MSTest test Results
    [Tt]est[Rr]esult*/
    [Bb]uild[Ll]og.*
    
    # NUNIT
    *.VisualState.xml
    TestResult.xml
    
    # Build Results of an ATL Project
    [Dd]ebugPS/
    [Rr]eleasePS/
    dlldata.c
    
    # DNX
    project.lock.json
    project.fragment.lock.json
    artifacts/
    
    *_i.c
    *_p.c
    *_i.h
    *.ilk
    *.meta
    *.obj
    *.pch
    *.pdb
    *.pgc
    *.pgd
    *.rsp
    *.sbr
    *.tlb
    *.tli
    *.tlh
    *.tmp
    *.tmp_proj
    *.log
    *.vspscc
    *.vssscc
    .builds
    *.pidb
    *.svclog
    *.scc
    
    # Chutzpah Test files
    _Chutzpah*
    
    # Visual C++ cache files
    ipch/
    *.aps
    *.ncb
    *.opendb
    *.opensdf
    *.sdf
    *.cachefile
    *.VC.db
    *.VC.VC.opendb
    
    # Visual Studio profiler
    *.psess
    *.vsp
    *.vspx
    *.sap
    
    # TFS 2012 Local Workspace
    $tf/
    
    # Guidance Automation Toolkit
    *.gpState
    
    # ReSharper is a .NET coding add-in
    _ReSharper*/
    *.[Rr]e[Ss]harper
    *.DotSettings.user
    
    # JustCode is a .NET coding add-in
    .JustCode
    
    # TeamCity is a build add-in
    _TeamCity*
    
    # DotCover is a Code Coverage Tool
    *.dotCover
    
    # NCrunch
    _NCrunch_*
    .*crunch*.local.xml
    nCrunchTemp_*
    
    # MightyMoose
    *.mm.*
    AutoTest.Net/
    
    # Web workbench (sass)
    .sass-cache/
    
    # Installshield output folder
    [Ee]xpress/
    
    # DocProject is a documentation generator add-in
    DocProject/buildhelp/
    DocProject/Help/*.HxT
    DocProject/Help/*.HxC
    DocProject/Help/*.hhc
    DocProject/Help/*.hhk
    DocProject/Help/*.hhp
    DocProject/Help/Html2
    DocProject/Help/html
    
    # Click-Once directory
    publish/
    
    # Publish Web Output
    *.[Pp]ublish.xml
    *.azurePubxml
    # TODO: Comment the next line if you want to checkin your web deploy settings
    # but database connection strings (with potential passwords) will be unencrypted
    *.pubxml
    *.publishproj
    
    # Microsoft Azure Web App publish settings. Comment the next line if you want to
    # checkin your Azure Web App publish settings, but sensitive information contained
    # in these scripts will be unencrypted
    PublishScripts/
    
    # NuGet Packages
    *.nupkg
    # The packages folder can be ignored because of Package Restore
    **/packages/*
    # except build/, which is used as an MSBuild target.
    !**/packages/build/
    # Uncomment if necessary however generally it will be regenerated when needed
    #!**/packages/repositories.config
    # NuGet v3's project.json files produces more ignoreable files
    *.nuget.props
    *.nuget.targets
    
    # Microsoft Azure Build Output
    csx/
    *.build.csdef
    
    # Microsoft Azure Emulator
    ecf/
    rcf/
    
    # Windows Store app package directories and files
    AppPackages/
    BundleArtifacts/
    Package.StoreAssociation.xml
    _pkginfo.txt
    
    # Visual Studio cache files
    # files ending in .cache can be ignored
    *.[Cc]ache
    # but keep track of directories ending in .cache
    !*.[Cc]ache/
    
    # Others
    ClientBin/
    ~$*
    *~
    *.dbmdl
    *.dbproj.schemaview
    *.pfx
    *.publishsettings
    node_modules/
    orleans.codegen.cs
    
    # Since there are multiple workflows, uncomment next line to ignore bower_components
    # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
    #bower_components/
    
    # RIA/Silverlight projects
    Generated_Code/
    
    # Backup & report files from converting an old project file
    # to a newer Visual Studio version. Backup files are not needed,
    # because we have git ;-)
    _UpgradeReport_Files/
    Backup*/
    UpgradeLog*.XML
    UpgradeLog*.htm
    
    # SQL Server files
    *.mdf
    *.ldf
    
    # Business Intelligence projects
    *.rdl.data
    *.bim.layout
    *.bim_*.settings
    
    # Microsoft Fakes
    FakesAssemblies/
    
    # GhostDoc plugin setting file
    *.GhostDoc.xml
    
    # Node.js Tools for Visual Studio
    .ntvs_analysis.dat
    
    # Visual Studio 6 build log
    *.plg
    
    # Visual Studio 6 workspace options file
    *.opt
    
    # Visual Studio LightSwitch build output
    **/*.HTMLClient/GeneratedArtifacts
    **/*.DesktopClient/GeneratedArtifacts
    **/*.DesktopClient/ModelManifest.xml
    **/*.Server/GeneratedArtifacts
    **/*.Server/ModelManifest.xml
    _Pvt_Extensions
    
    # Paket dependency manager
    .paket/paket.exe
    paket-files/
    
    # FAKE - F# Make
    .fake/
    
    # JetBrains Rider
    .idea/
    *.sln.iml
    
    
    

    external by jakkaj  22  0  1  0

    JWT Validation using ASP.NET Core build in stuff

    JWT Validation using ASP.NET Core build in stuff: TokenValidationParamsSettings.cs
    //From <https://stormpath.com/blog/token-authentication-asp-net-core>
    
    var tokenValidationParameters = new TokenValidationParameters
    {
      // The signing key must match!
      ValidateIssuerSigningKey = true,
      IssuerSigningKey = signingKey,
    
      // Validate the JWT Issuer (iss) claim
      ValidateIssuer = true,
      ValidIssuer = "ExampleIssuer",
    
      // Validate the JWT Audience (aud) claim
      ValidateAudience = true,
      ValidAudience = "ExampleAudience",
    
      // Validate the token expiry
      ValidateLifetime = true,
    
      // If you want to allow a certain amount of clock drift, set that here:
      ClockSkew = TimeSpan.Zero
    };
    
    app.UseJwtBearerAuthentication(new JwtBearerOptions
    {
      AutomaticAuthenticate = true,
      AutomaticChallenge = true,
      TokenValidationParameters = tokenValidationParameters
    });
    
     
    
    
    • Public Snippets
    • Channels Snippets