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

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

找不到 C# netcore 控制器

找不到 C# netcore 控制器

C#
胡子哥哥 2021-07-22 19:16:06
我在現(xiàn)有的 IdentityServer4 項(xiàng)目中添加了一個(gè) netcore 控制器。這是我的代碼namespace IdentityServer4.Quickstart.UI{  public class VersionController : Controller  {    IVersionService _repository;    public VersionController(IVersionService repository)    {        _repository = repository;    }    [HttpGet(nameof(GetBackgroundId))]    public IActionResult GetBackgroundId()    {        return new OkObjectResult(_repository.GetBackgroundId());    }    [HttpPut(nameof(SetBackgroundId))]    public IActionResult SetBackgroundId([FromQuery]int id)    {        _repository.SetBackgroundId(id);        return new NoContentResult();    } }}我在startup.cs中也有以下代碼行app.UseMvcWithDefaultRoute();我可以通過(guò)以下網(wǎng)址訪(fǎng)問(wèn)帳戶(hù)控制器http://localhost:5001/account/login但是,我無(wú)法通過(guò)以下網(wǎng)址訪(fǎng)問(wèn)版本控制器:http://localhost:5001/version/GetBackgroundId錯(cuò)誤代碼是 404。怎么了?
查看完整描述

1 回答

?
jeck貓

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

您缺少控制器的路由前綴。您正在使用屬性路由,因此您需要包含整個(gè)所需的路由。


當(dāng)前GetBackgroundId控制器操作將映射到


http://localhost:5001/GetBackgroundId

添加路由到控制器


[Route("[controller]")]

public class VersionController : Controller {

    IVersionService _repository;

    public VersionController(IVersionService repository) {

        _repository = repository;

    }


    //Match GET version/GetBackgroundId

    [HttpGet("[action]")]

    public IActionResult GetBackgroundId() {

        return Ok(_repository.GetBackgroundId());

    }


    //Match PUT version/SetBackgroundId?id=5

    [HttpPut("[action]")]

    public IActionResult SetBackgroundId([FromQuery]int id) {

        _repository.SetBackgroundId(id);

        return NoContent();

    }

 }

還要注意路由令牌的使用,而不是更新響應(yīng),Controller已經(jīng)有提供這些結(jié)果的輔助方法。


查看完整回答
反對(duì) 回復(fù) 2021-07-31
  • 1 回答
  • 0 關(guān)注
  • 259 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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