小编arp*_*tro的帖子

如何在.net核心中使用Swagger Codegen

我可以使用Swashbuckle在我的web api中集成Swagge UI.我也想探索swagger codegen功能.有人可以帮忙 - 我如何将swagger codegen集成到我的web api项目中?或者我需要下载任何工具吗?我希望它能够托管codegen并传递json/raml表单规范以在.net核心中生成客户端.

我无法在上面找到足够的文档.

编辑:我想知道如何在WEBAPI中托管codegen.

谢谢!

c# .net-core swagger-codegen

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

针对 webapi dotnet core 中的 ApiVersioning 错误的自定义错误响应

我正在为 Webapi 服务中的所有错误创建一个包库。该库将用于为 BadRequest、BadArgument、ApiVersionsing 等相关错误提供自定义响应。我需要帮助自定义 Apiversion 相关错误 - ApiVersionUnspecified、UnsupportedApiVersion、InvalidApiVersion、AmbiguousApiVersion。我已经按照这篇文章为我的项目包含 api-versioning - https://www.hanselman.com/blog/ASPNETCoreRESTfulWebAPIVersioningMadeEasy.aspx

我已经检查了上述包的 github wiki,发现“根据所需的行为,您可以扩展 DefaultErrorResponseProvider 或者您可以从 stratch 实现您自己的 IErrorResponseProvider。

要连接备用错误响应行为,请将默认提供程序替换为您自己的:”

options => options.ErrorResponses = new MyErrorResponseProvider();
Run Code Online (Sandbox Code Playgroud)

然而; 我不太明白如何自定义 MyErrorResponseProvider 类中的默认错误响应。有人可以为我提供任何示例,以便我可以开始使用吗?

提前致谢!

c# error-handling custom-error-handling .net-core api-versioning

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

EnumDataType()属性验证错误消息未显示

在我的.net core 2.0 Web API中,我在模型属性上使用EnumDataType()验证属性。验证失败时,自定义错误消息为空。我不确定为什么会这样-

EnumDataType(typeof(MyEnum), ErrorMessage = "Custom Error Message")
public MyEnum MyEnumProp {get; set;}
Run Code Online (Sandbox Code Playgroud)

我检查了其他具有[Required],[MinLength]的属性,并且所有属性均生成自定义错误消息。难道我做错了什么?还有其他方法吗?

enums data-annotations asp.net-core asp.net-core-2.0

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

多个图像上传和预览

我正在学习如何上传多个图像并显示他们的预览......

我遇到了以下代码

<html>
<head>
<style>
.input-file-row-1:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}

.input-file-row-1{
display: inline-block;
margin-top: 25px;
position: relative;
}

#preview_image {
display: none;
width: 90px;
height: 90px;
margin: 2px 0px 0px 5px;
border-radius: 10px;
}

.upload-file-container { 
position: relative; 
width: 100px; 
height: 137px; 
overflow: hidden;   
background: url('images/picplus.png') top center no-repeat;
float: left;
margin-left: 23px;
} 

.upload-file-container-text{
font-family: Arial, sans-serif;
font-size: 12px;
color: #719d2b;
line-height: 17px;
text-align: center;
display: block;
position: absolute; …
Run Code Online (Sandbox Code Playgroud)

javascript css jquery html5 image-upload

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

想根据输入数字C#查找日期

我希望能够根据输入数字找到日期(1-365之间).例如,如果输入的数字为40,那么我的程序应该输出 - 日期:9月:2 我尝试了以下代码,并且能够找到除1月以外的所有月份的日期 -

static void Main(string[] args)
{
    int[] arryofdays = new int[] {31,28,31,30,31,30,31,31,30,31,30,31};
    int num = Int32.Parse(Console.ReadLine());
    int temp = num;
    string date, month;

    for (int i = 0; i < arryofdays.Length; i++)
    {        
        temp = temp - arryofdays[i];
        if (temp < arryofdays[i + 1])
        {
            Console.WriteLine("Date:" + temp.ToString());
            Console.WriteLine("Month:" + (i+2).ToString());
            break;
        }
    }

    Console.ReadLine();
}
Run Code Online (Sandbox Code Playgroud)

请帮忙!

c# datetime

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

自定义中间件,用于输入验证

我的API只有POST操作方法。我想创建一个库来验证对我的API的输入。现在,我想在点击控制器操作方法之前进行此验证。

我决定使用中间件方法-

public class ValidateInputMiddleware
{
    private readonly RequestDelegate _next;

    public ValidateInputMiddleware(RequestDelegate next)
    {
        _next = next;
    }

    public async Task Invoke(HttpContext httpContext)
    {
        //read the request body

        //serialize the json body to input model

        //validations
        if(reqJsonObj.Id == null)
            //return response - id is null

        //other validations

        await _next(httpContext);
    }
}
Run Code Online (Sandbox Code Playgroud)

如果满足我的验证条件,那么我不希望管道中的其他项目执行。

我需要帮助-

  1. 我如何限制执行中的其他项目。

  2. 如何以JSON形式返回自定义的错误响应。

c# validation asp.net-core-middleware asp.net-core-2.0

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