相关疑难解决方法(0)

ASP.NET Web API中的自定义方法名称

我正在从WCF Web API转换为新的ASP.NET MVC 4 Web API.我有一个UsersController,我想要一个名为Authenticate的方法.我看到了如何进行GetAll,GetOne,Post和Delete的示例,但是如果我想在这些服务中添加额外的方法呢?例如,我的UsersService应该有一个名为Authenticate的方法,它会传入用户名和密码,但是它不起作用.

public class UsersController : BaseApiController
{
    public string GetAll()
    {
        return "getall!";
    }

    public string Get(int id)
    {
        return "get 1! " + id;
    }

    public User GetAuthenticate(string userName, string password, string applicationName)
    {
        LogWriter.Write(String.Format("Received authenticate request for username {0} and password {1} and application {2}",
            userName, password, applicationName));

        //check if valid leapfrog login.
        var decodedUsername = userName.Replace("%40", "@");
        var encodedPassword = password.Length > 0 ? Utility.HashString(password) : String.Empty;
        var leapFrogUsers = LeapFrogUserData.FindAll(decodedUsername, …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-web-api asp.net-web-api-routing

109
推荐指数
6
解决办法
15万
查看次数

Web api 中的 Swagger 500 错误

当我访问 swagger url: 时http//localhost:50505/swagger/index。我收到了 500 错误。

请帮我弄清楚。

namespace BandwidthRestriction.Controllers
{
[Route("api/[controller]")]
public class BandwidthController : Controller
{
    private SettingDbContext _context;
    private readonly ISettingRespository _settingRespository;

    public BandwidthController(ISettingRespository settingRespository)
    {
        _settingRespository = settingRespository;
    }
    public BandwidthController(SettingDbContext context)
    {
        _context = context;
    }

    // GET: api/Bandwidth
    [HttpGet]
    public IEnumerable<Setting> GetSettings()
    {
        return _settingRespository.GetAllSettings();
    }

    // GET: api/Bandwidth/GetTotalBandwidth/163
    [HttpGet("{facilityId}", Name = "GetTotalBandwidth")]
    public IActionResult GetTotalBandwidth([FromRoute] int facilityId)
    {
        // ...
        return Ok(setting.TotalBandwidth);
    }

    // GET: api/Bandwidth/GetAvailableBandwidth/163
    [HttpGet("{facilityId}", Name = "GetAvailableBandwidth")]
    public IActionResult …
Run Code Online (Sandbox Code Playgroud)

asp.net asp.net-web-api swagger swashbuckle asp.net-core

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