Giter VIP home page Giter VIP logo

aspnetcore.docs.samples's People

Contributors

alexwolfmsft avatar billwagner avatar brunolins16 avatar captainsafia avatar fiyazbinhasan avatar gfoidl avatar jeremylikness avatar jvandertil avatar logiclrd avatar maartenba avatar martincostello avatar richlander avatar rick-anderson avatar sammychinedu2ky avatar seekdavidlee avatar serpent5 avatar tdykstra avatar timdeschryver avatar wadepickett avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aspnetcore.docs.samples's Issues

.NET 7 RC1 improvements to Rate limiting middleware

Rate limiting middleware improvements

  • Code to update
  • Add [EnableRateLimitingAttribute("MyControllerPolicy")] to Home2Controller
  • disable rate limiting on a specific endpoint within that group
  • apply policies directly to endpoints.
  • add an instance of it directly to an endpoint
  • Add
builder.Services.AddRateLimiter(options =>
{
   options.AddTokenBucketLimiter("MyControllerPolicy", options =>
   {
       options.TokenLimit = 1;
       options.QueueProcessingOrder = QueueProcessingOrder.OldestFirst;
       options.QueueLimit = 1;
       options.ReplenishmentPeriod = TimeSpan.FromSeconds(10);
       options.TokensPerPeriod = 1;
   })
   .AddPolicy<string>("MyGroupPolicy", new MyRateLimiterPolicy());
});

Then @Rick-Anderson can update Rate limiting middleware in ASP.NET Core

@Kahbazi can you do these updates?

Also, the updates requested in #14

separate the unit tests from the integration tests into different projects

See the note just above Test app prerequisites

When creating a test project for an app, separate the unit tests from the integration tests into different projects. This helps ensure that infrastructure testing components aren't accidentally included in the unit tests. Separation of unit and integration tests also allows control over which set of tests are run.

@fiyazbinhasan can you split out your integration and unit tests?

Typed results for minimal APIs

See Typed results for minimal APIs

It would be great to have the sample from that blog here. You can get the starter project code from https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/tutorials/first-web-api/samples/6.0/TodoApi

Create your new project in a new folder typed-results under https://github.com/dotnet/AspNetCore.Docs.Samples/tree/main/fundamentals/minimal-apis/samples

See tests in https://github.com/dotnet/aspnetcore/tree/main/src/Mvc/Mvc.ApiExplorer/test

cc @sammychinedu2ky if you're interested.

@brunolins16 is the expert on this. See dotnet/aspnetcore#40656

Rate limiter provides no feedback when limit is hit

Consider the following code:

using Microsoft.AspNetCore.RateLimiting;
using System.Threading.RateLimiting;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddRateLimiter(_ => _
    .AddFixedWindowLimiter(policyName: "fixed", options =>
    {
        options.PermitLimit = 4;
        options.Window = TimeSpan.FromSeconds(120);
        options.QueueProcessingOrder = QueueProcessingOrder.OldestFirst;
        options.QueueLimit = 2;
    }));

var app = builder.Build();

app.UseRateLimiter();

static string GetTicks() => (DateTime.Now.Ticks & 0x11111).ToString("00000");

app.MapGet("/", () => Results.Ok($"Hello {GetTicks()}"))
                           .RequireRateLimiting("fixed");

app.Run();

Browse to / on localhost and quickly hit refresh multiple times. After the rate limit is hit, the browser doesn't show a problem, it's displaying the last response. F12 tools don't show any thing and there is nothing in the log.

@wtgodbe how can the client be notified? What's the best way to log this? Why isn't the default rejection status 503 returned?
cc @fiyazbinhasan

Antiforgery integration for minimal APIs

See Antiforgery integration for minimal APIs

and this sample

In this code I pass in the action so

app.MapGet("/DisableAntiforgery", () =>
{
    return Results.Content(MyHtml.html("/todo"), "text/html");
});

app.MapGet("/post2", () =>
{
    return Results.Content(MyHtml.html("/todo2"), "text/html");
});

Can use the same HTML when they pass in the action arg.

Is there a clean way to do this to pass in an arg for

<input name="{token.FormFieldName}" 
                              type="hidden" value="{token.RequestToken}" />

Maybe that makes things too messy. Perhaps I should duplicate most of the HTML and not get the HTML from a method while passing the action.

public static string html2(string action, AntiforgeryTokenSet token) => $"""
    <html><body>
        <form action="{action}" method="POST" enctype="multipart/form-data">
            <input name="{token.FormFieldName}" 
                          type="hidden" value="{token.RequestToken}" />
            <input type="text" name="name" />
            <input type="date" name="dueDate" />
            <input type="checkbox" name="isCompleted" />
            <input type="submit" />
        </form>
    </body></html>
""";

Works, but I'm not sure it's an improvement. There's no way to pass in a null token.

@sammychinedu2ky @david-acker

cc @guardrex

Example of Using 2FA with ASP.NET Core Identity and Angular

Hello everyone!

I've been delving into the Identity Documentation, particularly the sections covering 2FA with Razor Pages, and it's been an enlightening experience!

However, I'm currently facing a gap in documentation when it comes to integrating 2FA with Single Page Applications (SPAs).

Would it be possible to provide a comprehensive example for 2FA with ASP.NET Core Identity and Angular? I'm specifically interested in understanding how to leverage endpoints for seamless SPA integration. Unfortunately, I couldn't find any information related to 2FA TOTP in the Angular Sample.

This addition would immensely benefit developers looking for a thorough guide on 2FA integration with Angular. Your efforts in this regard would be highly appreciated! Thank you!

Which license applies to the examples?

Could you please provide the license information for your examples? We are uncertain which license applies to the examples and would appreciate it if you could add the relevant license information to the repository. Additionally, we would like to confirm if it is permissible to use the examples (e.g. test/integration-tests/IntegrationTestsSample) in our own public repository. Thank you.

app.MapPost("/fileUp", async (IFormFile file)

See https://devblogs.microsoft.com/dotnet/asp-net-core-updates-in-net-7-preview-1/
Put in https://github.com/dotnet/AspNetCore.Docs.Samples/tree/main/fundamentals/minimal-apis/samples/IFormFile

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/", () => "Hello World!");

app.MapPost("/fileUp", async (IFormFile file) =>
{
    string tempfile = Path.GetTempFileName();
    using var stream = File.OpenWrite(tempfile);
    await file.CopyToAsync(stream);
});

app.MapPost("/FilesUp", async (IFormFileCollection myFiles) =>
{
    foreach (var file in myFiles)
    {
        string tempfile = Path.GetTempFileName();
        using var stream = File.OpenWrite(tempfile);
        await file.CopyToAsync(stream);
    }
});

app.Run();

Update readme.txt with instructions on testing.

Clean up IAuthorizationRequirementData

See Improved support for custom authorization policies with IAuthorizationRequirementData

ToDo:

  • Fix all the null warnings and other warnings
  • Fix 415 error

See the project here

  1. Create a token and DOB via this command and save token
  2. run the app
  3. curl -i -H "Authorization: Bearer <token>" http://localhost:{port}/api/greetings/hello

Output shows:

Evaluating authorization requirement for age >= 16
info: MinimumAgeAuthorizationHandler[0]
      Minimum age authorization requirement 16 satisfied

But request returns a 415 error.

@kevinchalet can you help? CC @jxwaters if you can help

contributes to dotnet/AspNetCore.Docs#29291

IProblemDetailsService.WriteAsync with API controller

See the middleware version

/api/values/Squareroot/-1 returns the generic type and title
{"type":"https://tools.ietf.org/html/rfc7231#section-6.5.1","title":"Bad Request",
not the type and title that's set
{"type":"https://en.wikipedia.org/wiki/Square_root","title":"Wrong Input"

When I Customize problem details with CustomizeProblemDetails see also source code

the API controller returns the correct problem details.

When I step through the middleware version in the debugger, everything is set correctly.

@sammychinedu2ky

Update validation sample to include Name and ShortName

Update the model:

public class Contact
{
    public int Id { get; set; }

    public string Name { get; set; } = String.Empty;
    public string ShortName { get; set; } = String.Empty;
    public string Email { get; set; } = String.Empty;
    public string PhoneNumber { get; set; } = String.Empty;
}

Then have a validation check like:

        if (Contact.Name == Contact.ShortName) {
            ModelState.AddModelError(nameof(Contact.ShortName),
                                               "Short name can't be the same as Name.");
        }

Code at https://github.com/dotnet/AspNetCore.Docs.Samples/tree/main/mvc/models/ModelStateError

It's easier to delete the existing code and create a new project and scaffold it.

Bonus points if you move from MVC to Razor Pages.


Document Details

โš  Do not edit this section. It is required for learn.microsoft.com โžŸ GitHub issue linking.


Why is that necessary?

Trying to do the Arrangement based on IndexPageTests.cs but a failure came and said that no such table.

Until

db.Database.EnsureCreated();

was added in a line before

Utilities.ReinitializeDbForTests(db);

So it's look like this
db.Database.EnsureCreated();
Utilities.ReinitializeDbForTests(db);

I am wondering, why is it necessary

https://github.com/dotnet/AspNetCore.Docs.Samples/blob/main/test/integration-tests/IntegrationTestsSample/tests/RazorPagesProject.Tests/IntegrationTests/IndexPageTests.cs

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.