第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

控制器的正確網(wǎng)址

控制器的正確網(wǎng)址

C#
慕田峪9158850 2021-11-21 18:02:35
你能告訴我什么是控制器方法 GetProfileById 的正確 url 與屬性 'id' 我嘗試了很多 url,如 ' http://localhost:5000/api/Profile/GetProfileById/1 '、' http://localhost:5000/ api/Profile/ProfileById/1 ',' http://localhost:5000/api/ProfileById/1 ' 但 Postman 顯示消息 'Cannot Get and my url'這是代碼:using System.Threading.Tasks;using Microsoft.AspNetCore.Authorization;using Microsoft.AspNetCore.Mvc;using SocialNetwork.Repositories;using SocialNetwork.Repositories.GenericRepository;namespace SocialNetwork.Controllers{    [Route("/api/[controller]")]    public class ProfileController : Controller    {        private readonly ProfileRepository repository;        public ProfileController(IProfileRepository repository)        {            this.repository = (ProfileRepository)repository;        }        [HttpGet("{id}")]        [ProducesResponseType(200, Type = typeof(Profile))]        [ProducesResponseType(404)]        public async Task<ActionResult<Profile>> GetProfileById(int id)        {            var profile = await repository.GetById(id);            if(profile != null)            {                return new OkObjectResult(Json(profile));            }            return NotFound();        }}}
查看完整描述

2 回答

?
波斯汪

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超4個(gè)贊

應(yīng)該是/api/profile/<id>。您可以通過(guò)[Route("/api/[controller]")]方法上方的指令來(lái)說(shuō)明這一點(diǎn)。然后,任何 id 都在后面的一個(gè)斜杠之后添加。

因此,您localhost(或您的域)的完整路由將是http://localhost:5000/api/Profile/1


查看完整回答
反對(duì) 回復(fù) 2021-11-21
?
慕哥6287543

TA貢獻(xiàn)1831條經(jīng)驗(yàn) 獲得超10個(gè)贊

路由到 ASP.NET Core 中的控制器操作”和“ ASP.NET Core 中的路由”是用于此目的的好文章。

在您的情況下,正確的 URL 是“ http://localhost:5000/api/profile/1 ”。

注意:如果使用 Postman 仍有問(wèn)題,請(qǐng)搜索如何配置它。


查看完整回答
反對(duì) 回復(fù) 2021-11-21
  • 2 回答
  • 0 關(guān)注
  • 236 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)