再见,
我正在开发一个asp.net web api核心(目标框架.NET Core 2.1).我正在使用Swagger规范记录我的API.我选择使用Swashbuckle.AspNetCore库.
我有一个简单的创建操作,如下所示:
/// <summary>
/// My summary
/// </summary>
/// <remarks>My remarks</remarks>
/// <param name="value">value</param>
/// <response code="201">Created</response>
/// <response code="400">Data not valid</response>
/// <response code="500">Internal Server Error</response>
[HttpPost]
public IActionResult Post([FromBody, BindRequired] EntityDto value)
{
...
}
Run Code Online (Sandbox Code Playgroud)
问题是我生成的swagger.json自动创建了"200响应".但因为我的动作只创建实体,所以它只返回201响应.这是以下json片段:
{
...
"responses": {
"200": {
"description": "Success"
},
"201": {
"description": "Created"
},
"400": {
"description": "Data not valid"
},
"500": {
"description": "Internal Server Error"
}
}
...
}
Run Code Online (Sandbox Code Playgroud)
在互联网上冲浪我发现SwaggerResponseRemoveDefaults属性,但似乎只在Full …
我正在使用OAuth2隐式流程开发Angular 5应用程序.
我有服务执行HTTP调用,遵循我的服务示例:
@Injectable()
export class MyService {
constructor(public http: HttpClient) { }
public getAll(): Observable<Persona[]> {
return this.http.get<Persona[]>("http://mywebservice/persone");
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用拦截器进行授权并添加自定义属性.跟随我的auth拦截器:
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from "rxjs";
@Injectable()
export class AuthInterceptor implements HttpInterceptor {
constructor() {
}
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
let accessToken = sessionStorage.getItem("access_token");
if(accessToken)
{
request = request.clone({
setHeaders: {
Authorization: `Bearer ${accessToken}`
}
});
}
return next.handle(request);
}
} …Run Code Online (Sandbox Code Playgroud) 我正在使用Microsoft Web API 2和SwaggerUi开发RESTful Web服务.
我删除了默认的Global.asax,并使用OWIN配置了我的Web API.这是我的Startup.cs代码:
public void Configuration(IAppBuilder app)
{
HttpConfiguration config = new HttpConfiguration();
WebApiConfig.Register(config);
config.MessageHandlers.Add(new JWTAuthenticationHandler() { StopPipelineHandling = true });
config.Filters.Add(new MyActionFilter());
SwaggerConfig.Register();
app.UseWebApi(config);
}
Run Code Online (Sandbox Code Playgroud)
这是我的SwaggerConfig.cs代码:
GlobalConfiguration.Configuration
.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "MyNamespace.WebApi");
})
.EnableSwaggerUi(c =>
{});
Run Code Online (Sandbox Code Playgroud)
在此操作之后,我无法像下面的图像一样查看swagger上的操作:
拜托,你能帮帮我吗?
非常感谢
我正在开发一个Web api核心2.0项目。
我需要支持两种授权类型:jwt和basic。
在我的ConfigureServices方法中,我添加了以下代码:
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer((options) =>
{
options.Authority = $"...";
options.Audience = "...";
});
services.AddAuthentication(BasicAuthenticationDefaults.AuthenticationScheme)
.AddBasicAuthentication(credentials =>
Task.FromResult(
credentials.username == "username"
&& credentials.password == "password"));
Run Code Online (Sandbox Code Playgroud)
在我的Configure方法中,我添加了以下代码:
app.UseAuthentication();
app.UseMvc();
Run Code Online (Sandbox Code Playgroud)
最后,我在控制器上添加了AuthorizeAttribute:
[Authorize]
public class MioController : Controller
{ ... }
Run Code Online (Sandbox Code Playgroud)
实际上仅工作在ConfigureServices上指定的最后一次身份验证。
如何支持两种身份验证类型?谢谢
注意:我正在使用此NuGet包进行基本身份验证Bazinga.AspNetCore.Authentication.Basic。
我正在使用Visual Studio 2010.我必须生成一个这样的REPORT:
_________________________________
| NAME SURNAME | NAME SURNAME |
| ADDRESS | ADDRESS |
| NUMBER | NUMBER |
| | |
| NAME SURNAME | NAME SURNAME |
| ADDRESS | ADDRESS |
| NUMBER | NUMBER |
Run Code Online (Sandbox Code Playgroud)
但结果现在是这样的:
_________________________________
| NAME SURNAME | |
| ADDRESS | |
| NUMBER | |
| | |
| NAME SURNAME | |
| ADDRESS | |
| NUMBER | |
| | |
| NAME SURNAME | | …Run Code Online (Sandbox Code Playgroud) 我正在处理一个 Angular 4 项目,我是Observable 的新手。
我的目标是在三个 HTTP 请求的结果之后执行一个函数,并用 HTTP 请求结果丰富我的模型。
我用 observable 解决了我的问题,如以下代码,但我认为这不是正确的方法:
function loadData(callback: Function): void {
this.httpRequestUno().subscribe(next => {
this.httpRequestDue().subscribe(next => {
this.httpRequestTre().subscribe(next => {
callback();
}, error => {
console.log(error);
});
}, error => {
console.error(error);
});
}, error => {
console.error(error);
});
}
function httpRequestUno():Observable<any>{
let self = this;
return new Observable<any>((observer) => {
// my http request and...
self.attributo1 = httpResult;
observer.next(1);
});
}
function httpRequestDue():Observable<any>{
let self = this;
return new Observable<any>((observer) …Run Code Online (Sandbox Code Playgroud) 再见,
我对这个问题很沮丧,我创建了一个简单的类,如下所示:
public class Classe
{
public int Intero { get; set; }
public Int32 Intero32 { get; set; }
public double Double { get; set; }
public string Stringa { get; set; }
public Classe PerReferenza { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我编写了这个扩展方法,其目标是返回属性的引用默认值(引用的类型或值类型):
public static class TypeExtensions
{
public static object GetDefaultValue(this Type t)
{
if (t.IsValueType)
return Activator.CreateInstance(t);
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
按照我的主要方法:
static void Main(string[] args)
{
Classe c = new Classe();
foreach (var …Run Code Online (Sandbox Code Playgroud) 再见,
我正在使用 Angular 8,但在对“计算”列进行排序时遇到问题。假设我有一个具有两个属性名称和描述的对象,如果我尝试将值与 .ts 文件内的函数连接,则排序不起作用。
这是我的标记:
<div class="col-md-12">
<div class="row">
<div class="example-container mat-elevation-z8">
<mat-table [dataSource]="dataSource" matSort>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
<ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef mat-sort-header> TOKEN NAME </mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.name}} </mat-cell>
</ng-container>
<ng-container matColumnDef="description">
<mat-header-cell *matHeaderCellDef mat-sort-header> INDUSTRY </mat-header-cell>
<mat-cell *matCellDef="let row" [style.color]=""> {{row.description}} </mat-cell>
</ng-container>
<ng-container matColumnDef="namedescription">
<mat-header-cell *matHeaderCellDef mat-sort-header> NameDescription </mat-header-cell>
<mat-cell *matCellDef="let row" [style.color]=""> {{concatena(row)}} </mat-cell>
</ng-container>
</mat-table>
<mat-paginator #paginator [pageSizeOptions]="[5, 10, 25, 100]"></mat-paginator>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
import { Component, …Run Code Online (Sandbox Code Playgroud)
我必须运行n查询SQL以更新更多数据库.我创建了一个批处理文件来帮助我完成此活动,但查询不是按名称排序执行的.
我使用这个批处理命令:
for %%I in (.\*.sql) DO sqlcmd -S .\istance -U username -P password -d dbname -i %%I -o .\%%I.log
Run Code Online (Sandbox Code Playgroud)
如何运行按名称排序的所有查询?
感谢您的回答.
注意:我使用的是Windows 7.
c# ×5
angular ×3
typescript ×3
.net-core ×2
asp.net-core ×2
batch-file ×1
for-loop ×1
interceptor ×1
json ×1
mat-table ×1
oauth-2.0 ×1
observable ×1
rdlc ×1
rxjs ×1
sorting ×1
sqlcmd ×1
swagger ×1
swagger-ui ×1
swashbuckle ×1