小编Gri*_*dko的帖子

在 Stripe CLI 中使用 Stripe webhook 时出现问题

我在 ASP.NET Web 表单应用程序中使用 Stripe Checkout 来让人们支付订阅费用,并且这部分代码工作正常。我使用以下代码创建了一个 webhook:

using Stripe;
using Stripe.Checkout;
using System.IO;
using System.Web;
using System;

namespace BNet {
    public class spdata : IHttpHandler {

        public void ProcessRequest ( HttpContext ctx ) {
            try {
                var epSecret = "whsec_u...";
                var json = new StreamReader(ctx.Request.InputStream).ReadToEnd();
                FileOps.WriteFile ("~/files/output.txt", "testing", out _, out _ );
                var sig = ctx.Request.Headers["Stripe-Signature"];
                try {
                    var se = EventUtility.ConstructEvent(
                    json,
                    sig,
                    epSecret
                );
                    if ( se.Type == "checkout.session.completed" ) {
                        var session = se.Data.Object as …
Run Code Online (Sandbox Code Playgroud)

c# asp.net webhooks stripe-payments

7
推荐指数
2
解决办法
6855
查看次数

APIGatewayProxyFunction 的空引用异常

我终于设法让我的 API 进入可以将其上传到 AWS Lambda 的状态,然后每当我尝试使用 API Gateway 测试它时,都会收到以下错误。

{
  "errorType": "AggregateException",
  "errorMessage": "One or more errors occurred. (Object reference not set to an instance of an object.)",
  "stackTrace": [
    "at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)",
    "at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)",
    "at lambda_method(Closure , Stream , Stream , ContextInfo )"
  ],
  "cause": {
    "errorType": "NullReferenceException",
    "errorMessage": "Object reference not set to an instance of an object.",
    "stackTrace": [
      "at Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction.MarshallRequest(InvokeFeatures features, APIGatewayProxyRequest apiGatewayRequest)",
      "at Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction.<FunctionHandlerAsync>d__12.MoveNext()"
    ]
  }
}

Run Code Online (Sandbox Code Playgroud)

代码:

public class LambdaEntryPoint : Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction
{ …
Run Code Online (Sandbox Code Playgroud)

c# amazon-web-services aws-lambda aws-api-gateway asp.net-core

6
推荐指数
1
解决办法
5565
查看次数

如何在 MVC4 中使用 Html.ListBoxFor

我正在尝试填充一个列表框。我的模型只是一个列表。我找不到我需要与@Html.ListBoxFor() 一起使用的参数的简单解释。

这是我的代码的一部分:

public ActionResult Index()
{
     List<string> names = GetAllNames();

    return View(names);
}

...
Run Code Online (Sandbox Code Playgroud)

在视图中:

@model List<string>

...

@Html.ListBoxFor(?)
Run Code Online (Sandbox Code Playgroud)

谢谢。

c# asp.net-mvc-4

5
推荐指数
1
解决办法
2万
查看次数

将多选列表发布到对象列表 asp.net core 2

我有两个类,称为UserRole

class User
{
    ...
    public List<Role> Roles;
}

class Role
{
    ...
    public int ID;
    public string Name;
}
Run Code Online (Sandbox Code Playgroud)

我也有一个动作(提交)

public IActionResult Submit(User user)
{
    ...
} 
Run Code Online (Sandbox Code Playgroud)

在我的 Index.cshtmlselect

<select multiple="multiple" class="multi-select" id="my_multi_select1" asp-for="Roles" asp-items="ViewBag.Roles"></select> 
Run Code Online (Sandbox Code Playgroud)

ViewBag.Roles价值是

ViewBag.Roles= new SelectList(Role.SelectAll(), "Name", "Name");
Run Code Online (Sandbox Code Playgroud)

问题是,当我发表我的表单,数据这样的发送 ...&Roles=role1,role2&...user.Roles成为空,而我希望有两个角色与名字role1,并role2和它们分配到user.Roles(实际上,我希望ASP这是否)

c# model-binding multi-select asp.net-core-2.0

5
推荐指数
1
解决办法
1万
查看次数

Linq2db:查询对象层次结构的有效方法

我使用 ac# 和 linq2db 并具有以下类/表层次结构:

public class YearlyTemplate
{
    [Column]
    public int Id { get; set; }
    public List<MonthlyTemplate> MonthlyTemplates { get; set;}
}

public class MonthlyTemplate
{
    [Column]
    public int Id { get; set; }

    [Column]
    public int YearlyTemplateId { get; set; }

    public YearlyTemplate YearlyTemplate{ get; set; }

    public List<DailyTemplate> DailyTemplates { get; set;}
}

public class DailyTemplate
{
    [Column]
    public int Id { get; set; }

    [Column]
    public int MonthlyTemplateId { get; set; }
    
    public MonthlyTemplate MonthlyTemplate …
Run Code Online (Sandbox Code Playgroud)

c# postgresql linq2db

4
推荐指数
1
解决办法
2822
查看次数

JWT WriterToken 函数抛出 IDX10653 错误

如标题, jwtSecurityTokenHandler.WriteToken(jwt) 函数抛出 IDX10653 错误。那里完全例外。

System.ArgumentOutOfRangeException: 'IDX10653: 
The encryption algorithm 'System.String' requires a key size of at least 'System.Int32' bits. 
Key 'Microsoft.IdentityModel.Tokens.SymmetricSecurityKey', is of size: 'System.Int32'. Arg_ParamName_Name
Run Code Online (Sandbox Code Playgroud)

我的示例用法如下:

public AccessToken CreateToken(User user, List<OperationClaim> operationClaims)
{
    _accessTokenExpiration = DateTime.Now.AddMinutes(_tokenOptions.AccessTokenExpiration);
    var securityKey = SecurityKeyHelper.CreateSecurityKey(_tokenOptions.SecurityKey);
    var signingCredentials = SigningCredentialsHelper.CreateSigningCredentials(securityKey);
    var jwt = CreateJwtSecurityToken(_tokenOptions, user, signingCredentials, operationClaims);
    var jwtSecurityTokenHandler = new JwtSecurityTokenHandler();
    var token = jwtSecurityTokenHandler.WriteToken(jwt);

    return new AccessToken
    {
        Token = token,
        Expiration = _accessTokenExpiration
    };
}
Run Code Online (Sandbox Code Playgroud)

我控制了我的每一个变量和函数。我认为没有错误,并且我没有找到该错误代码的任何解决方案。有什么解决办法吗?

编辑:在内部细节中额外的信息 - >

密钥“Microsoft.IdentityModel.Tokens.SymmetricSecurityKey”的大小为:“System.Int32”。(参数“键”) …

c# jwt .net-5

4
推荐指数
1
解决办法
4778
查看次数

在Asp.Net core 7中构建WebApplication之前调用Environment.IsDevelopment()

我有一个 Asp.net core 7 应用程序。app.Environment.IsDevelopment()在构建之前是否有类似的方法WebApplication

var builder = WebApplication.CreateBuilder(args);

// Can I call IsDevelopment() here?

var app = builder.Build();
if (app.Environment.IsDevelopment())
{
    //...
}
Run Code Online (Sandbox Code Playgroud)

我知道我可以使用环境变量,但我想知道是否已经存在标准方法。

c# asp.net-core

4
推荐指数
1
解决办法
995
查看次数

Razor 页面模型绑定错误上的 SelectList

我正在尝试按照此处的示例代码进行操作,但我一定遗漏了一些明显的内容。我没有从数据源中读取我的选择列表选项,而是尝试在构造函数中加载它们。但我不断收到错误消息。

InvalidOperationException: Could not create an instance of type 'Microsoft.AspNetCore.Mvc.Rendering.SelectList'. Model bound complex types must not be abstract, or value types and must have a parameterless constructor. Alternatively, set the 'SearchOptions' property to a non-null value.
Run Code Online (Sandbox Code Playgroud)

这是CS代码:

public class TestSelectModel : PageModel
{
    private List<SelectListItem> _searchoptions;
    [BindProperty(SupportsGet = true)]
    public SelectList SearchOptions { get; set; }
    public TestSelectModel()
    {
        _searchoptions = new List<SelectListItem>();
        _searchoptions.Add(new SelectListItem("By Email", "By Email", true));
        _searchoptions.Add(new SelectListItem("By Request Name", "By Request Name", false));
    } …
Run Code Online (Sandbox Code Playgroud)

c# razor-pages

3
推荐指数
1
解决办法
1816
查看次数

如何将多个选项的值从选择列表发布到 MVC 控制器?

我有一个如下所示的选择列表,我需要将选择列表中的每个选项的值发布到控制器。是否有可能以某种方式获得这些值?

选择列表

<select size="10" id="SelectedSortOrderOptions" name="SelectedSortOrderOptions">
    <option value="Parcel Number">Parcel Number</option>
    <option value="Receipt Number">Receipt Number</option>
    <option value="Municipality">Municipality</option>
</select>
Run Code Online (Sandbox Code Playgroud)

我可以在我的控制器中做类似的事情吗?

public IActionResult Submit(List<string> SelectedSortOrderOptions)
{
   ...
}
Run Code Online (Sandbox Code Playgroud)

Parcel Number我需要获取包含值、Receipt Number和的新字符串列表Municipality

c# asp.net-mvc multi-select asp.net-core

3
推荐指数
1
解决办法
6206
查看次数

ASP.NET Core Webb API 中的多个 HttpPost 方法

我无法在 ASP.NET Core 中处理我的路由规则。我有以下用户身份验证操作方法的后端和前端应用程序。由于这两种操作方法在有效载荷中都有一个参数不同或附加参数。Http 客户端实际上无法导航精确的方法,因此会抛出一个错误“歧义”的异常,这是真的,因为这两个 HttpPost 方法都有一个带有不同参数的参数。如何确保该方法根据操作触发。代码如下:-

API控制器:-

  [Route("api/[controller]")]
  public class AccountController: Controller
  {
         [HttpPost, ActionName("Login")]
         public async Task<IActionResult> UserLogin(LoginDto user)
         {
            //Code goes here
         }

        [HttpPost, ActionName("Register")]
        [ValidateAntiForgeryToken]
        public async Task<IActionResult> UserRegistration(RegisterDto register)
        {
             //Code goes here
        }
  }
Run Code Online (Sandbox Code Playgroud)

前端API服务

   public async Task<IActionResult> GetLoginAsync(LoginDto loginUser)
   {
                var request = "/api/account";
                var content = new StringContent(JsonConvert.SerializeObject(loginUser), Encoding.UTF8, "application/json");
                try
                {
                    var result = await ExecuteWithResiliencePolicies(() => _client.PostAsync(request, content));
                    return new StatusCodeResult((int)result.StatusCode);

                }
                catch (HttpRequestException)
                {
                    return new StatusCodeResult(StatusCodes.Status503ServiceUnavailable);
                }           
     } …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core-mvc asp.net-core asp.net-core-webapi

2
推荐指数
1
解决办法
5839
查看次数