asp.net-web-api 相关问题

ASP.NET Web API是一个用于为浏览器和移动设备等客户端构建HTTP服务的框架。它基于Microsoft .NET Framework,是构建RESTful服务的理想选择。

Web api vs2013 中“没有从服务器返回映射数据”?

我在vs2013中创建了新的web api mvc4项目。 我在 Page Inspector 中运行它,但它无法打开并报告以下警告: 服务器未返回任何映射数据。 我在 stackover 中找到了解决方案...

回答 1 投票 0

MVC4项目中的Web Api无法访问API控制器

我有一个包含许多控制器的 MVC4 项目。我在项目的根目录中添加了一个名为 BatchDetailsController 的 API 控制器。 我还创建了一个 WebApiConfig 类,如下所示: 公共站...

回答 1 投票 0

如何在 Angular 服务中调用 Web api

我是角度新手。有人可以帮助我知道如何用角度代码调用我的 api 吗? 我的 We API 是 - [HttpGet,Route("api/customer/getCustomer/{name}")] 公共异步任务 我是角度新手。有人可以帮助我知道如何用角度代码调用我的 api 吗? 我的 We API 是 - [HttpGet,Route("api/customer/getCustomer/{name}")] public async Task<IHttpActionResult> getCustomer([FromUri] string name) { ...} 在环形中,我尝试像下面这样打电话 - customer.component.ts - name = "test"; getCustomer(){ this.custService.getCustomer(this.name).subscribe((data) => { this.cust = JSON.parse(data.toString()); }); } 客户服务代码- getCustomer(name){ return this.http.get('https://localhost:44400/api/customer/getCustomer/', +name) } 客户.组件.ts export class CustomerComponent implements OnInit { name: string; cust: any; constructor(private custService: CustService){ } ngOnInit(){ this.name = "test"; this.getCustomer(); } getCustomer(){ this.custService.getCustomer(this.name).subscribe((data) => { this.cust = data; },error => { console.log(error); } ); } 我认为最好的实现是: 为您的服务器端 URL 定义一个配置文件: const serviceBaseUrl: 'https://localhost:44400/api', public getCustomer(name:string): Observable<Customer> { return this.httpClient.get<any>(`${serviceBaseUrl}/customer/getCustomer/`+name); } 首先在 app.module.ts 文件中导入 HttpClientModule 并设置导入: import { HttpClientModule } from '@angular/common/http'; imports: [ BrowserModule, HttpClientModule, ], 现在创建一个服务并将此代码添加到您的服务文件中 import { HttpClient } from '@angular/common/http'; export class EmployeeService { private url='Enter your api url'; constructor(private httpClient: HttpClient) { } getPost(){ return this.httpClient.get(this.url); } } 现在在 app.component.ts 文件中添加此代码 import {ApiService} from './services/api.service'; export class AppComponent { posts:any; constructor(private post:EmployeeService) {} ngOnInit(){ this.post.getPost().subscribe(response =>{ this.posts=response; console.log(this.posts); }) } } 现在在 app.component.html 文件中 <tr *ngFor="let post of posts"> <td>{{post.name}}</td> </tr> 现在完成,保存并运行您的应用程序 import { Injectable, model } from '@angular/core'; import { AddCategoryRequest } from '../models/add-category-request.model'; import { Observable } from 'rxjs'; import { HttpClient, HttpHeaders } from '@angular/common/http'; @Injectable({ providedIn: 'root' }) export class CategoryService { constructor(private http : HttpClient) { } addCategory(model: AddCategoryRequest): Observable<void> { return this.http.post<void>("https://localhost:7217/api/categories", model, { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) }); } } import { Component } from '@angular/core'; import { AddCategoryRequest } from '../models/add-category-request.model'; import { CategoryService } from '../services/category.service'; import { response } from 'express'; import { error } from 'console'; @Component({ selector: 'app-add-category', templateUrl: './add-category.component.html', styleUrl: './add-category.component.css' }) export class AddCategoryComponent { model : AddCategoryRequest; constructor(private categoryService : CategoryService){ this.model = { Name: '', UrlHandle: '', }; } onFormSubit() { this.categoryService.addCategory(this.model).subscribe({ next : (response) => { }, error : (error) => { } }); } } 型号 export interface AddCategoryRequest { Name: string; UrlHandle: string; }

回答 4 投票 0

无法使用 webapi .net 8.0 中的配置管理器读取 appsettings.json 连接字符串

我正在使用 .net 8.0 框架开发 asp.net webapi,我有下面的代码 在我的 DBContext 中 当我直接输入连接字符串时,效果很好 受保护覆盖无效

回答 1 投票 0

REST API 端点中异步后台代码执行的类型

我正在 ASP.NET 中实现 REST API 端点,它应该执行以下操作: 异步启动长时间运行的算法 返回 202 启动算法后立即接受(无等待)

回答 1 投票 0

C# 中异步代码执行的类型

我正在 ASP.NET 中实现 REST API 端点,它应该执行以下操作: 异步启动长时间运行的算法 返回 202 启动算法后立即接受(无等待)

回答 1 投票 0

无法加载文件或程序集 sapnco_utils.DLL 或其依赖项之一

我正在使用 VS 2022 64 位..当我尝试在本地运行我的 API 项目时..然后出现此错误.. 我已经尝试了 Stack Overflow 中的几乎所有解决方案..但它仍然不起作用。 喜欢干净...

回答 1 投票 0

403.18 - 禁止 指定的请求无法在 Web 服务器上为此资源配置的应用程序池中处理

我不明白为什么我会收到这篇文章标题中的错误。 我有一个网站在 .NET V4.0 中运行自己的应用程序池。 在网站下,我有一个应用程序在其自己的应用程序上运行...

回答 3 投票 0

如何将带有字节数组的json发送到Web api / postman

我希望能够发送给两者 1. 一个Web API 2.Postman 转 Web Api 我可以使用 Postman 对我的 Web Api 执行简单的 GET 请求,但我不明白如何发送字节数组。 与邮政...

回答 4 投票 0

HttpActionContext 在方法中给出错误消息

我今天将.net Framework 4.6中的webapi升级到8.0 web api core,收到错误消息 下面来自 IsAuthorized 方法 “类型或命名空间名称‘HttpActionContext’不能是...

回答 1 投票 0

允许非产品环境进行匿名身份验证

我们正在编写一个带有 Jwt 身份验证的 REST Api,需要了解如何允许非产品环境跳过 Jwt 身份验证功能。 我们无法在我们的控件上添加 [AllowAnonymous]...

回答 1 投票 0

账户锁定时间已满

我尝试在 .NET Core Web API 中实现的目标是防止默认帐户锁定行为。默认情况下,锁定的帐户将在 5 分钟后解锁。在我的系统中,锁定的帐户可以...

回答 3 投票 0

如何在 Web API 中支持 json 和 urlencoded 内容类型

我想在我的控制器/操作中支持以下所有 3 种内容类型。 应用程序/json 应用程序/x-www-form-urlencoded 多部分/表单数据 有了这个签名,我可以支持两个 urlen...

回答 3 投票 0

添加Swashbuckle备注时如何获取JSON格式?

我一直在关注 Swashbuckle 上的本教程,但是当我添加备注时,它们显示为常规文本,而不是备注部分中显示的 JSON。是否可以获取 JSON 格式?

回答 2 投票 0

保护 Web API/令牌端点

我有一个 Web API 项目,遵循此处概述的基本帐户身份验证流程:http://www.asp.net/web-api/overview/security/individual-accounts-in-web-api。我的问题是我应该看...

回答 1 投票 0

Swagger UI 检索参数错误

我想让员工使用用户名和密码进行注册和登录(1:1 关系)。但在 Swagger UI 中出现一些错误,参数检查照片以获取更多信息:错误和参数...

回答 2 投票 0

使用asp.net web api读取cookie

我有一个 JavaScript 客户端,它使用 document.cookie =“用户名=John Doe;过期=2019 年 12 月 18 日星期四 12:00:00 UTC”; 我想使用 ASP.NET Web API 在服务器端读取此 cookie (

回答 3 投票 0

比较Where子句中的ComplexType EFCore

我有一个名为 MSISDN 的复杂类型,如下所示: 公共课MSISDN { 公共字符串 NDC { 获取;放; } 公共字符串 CC { 获取;放; } 公共字符串SN { 获取;放; }...

回答 1 投票 0

WebAPI Selfhost:无法将多个参数绑定到请求的内容

下面的代码经过简化以显示必要性。我可以知道出了什么问题吗?我似乎无法使用 [FromBody] 属性检索两个参数(在本例中为 A 和 B)。 错误信息是...

回答 5 投票 0

使用ReferenceHandler.IgnoreCycles时Web API返回错误的JSON

我在 .NET Web API 实体框架项目中的两个模型之间存在多对一关系。每个模型都有一个到另一个模型的导航属性。正如预期的那样,这会生成一个“JsonException...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.