安装fluentvalidation.webapi后无法命中重复的控制器路线? [英] Unable to hit duplicate controller route after installing fluentvalidation.webapi?

查看:96
本文介绍了安装fluentvalidation.webapi后无法命中重复的控制器路线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我安装了Fluent

Recently i installed Fluent

我有两个项目-一个MVC和另一个Web Api项目.两者都有名为交易"控制器的相同控制器.流畅安装后,我遇到了Web API请求无法找到任何DealsController的问题.

I have two projects - one MVC and other Web Api project. Both have same controller named as Deals controller. After fluent installation, i got problem that web api request is not able to locate any DealsController.

在MVC的Gloabal asax- Application_Start方法中:

In MVC's Gloabal asax- Application_Start method:

protected void Application_Start(object sender, EventArgs e)
{
            System.Web.Http.GlobalConfiguration.Configure(CompanyName.Service.WebApiConfig.Register);
            CompanyName.RouteConfig.RegisterRoutes(System.Web.Routing.RouteTable.Routes);

}

这两个语句分别注册了mvc和web api的路由.

Both these statements registers the routes for mvc and web api respectively.

我有DealsController,在两个项目(MVC和Web Api)中都使用相同的名称.

I have DealsController, which is located with the same name in both the projects (MVC and Web Api).

这是MVC的DealsController:

This is MVC's DealsController:

public class DealsController : System.Web.Mvc.Controller
{
    public DealsController()
    {

    }
}

这是Web Apis Deals控制器:

This is Web Apis Deals controller:

public class DealsController : System.Web.Http.ApiController
{
    public DealsController()
        {

        }

    [Route("api/advantage/getDeals/")]
    public IHttpActionResult GetDeals([FromUri] CompanyName.Entity.Deals.Filters filter)
    {
    }
}

当我点击此Web api的方法时,从nuget发布fluentvalidation.webapi安装: http://localhost/api/advantage/getDeals/?cityId = 2& sc = 0& so = 1& pn = 1

Post fluentvalidation.webapi installation from nuget, when i am hitting this web api's method: http://localhost/api/advantage/getDeals/?cityId=2&sc=0&so=1&pn=1

我遇到以下错误:

消息":未找到与请求URI匹配的HTTP资源'

"Message": "No HTTP resource was found that matches the request URI 'http://localhost/api/advantage/getDeals/?cityId=2&sc=0&so=1&pn=1'.",

"MessageDetail":未找到与名为"advantage"的控制器匹配的类型."

"MessageDetail": "No type was found that matches the controller named 'advantage'."

我不知道在安装Fluent验证Web API软件包后究竟发生了什么.我刚刚安装了fluentvalidation.webapi软件包,该软件包给了我一些与cors相关的错误,所以我进一步安装了Microsoft.AspNet.WebApi.Cors.

I dont know what exactly is happening post installation of fluent validation web api package. I just installed fluentvalidation.webapi package which gave me some cors related error, so i further installed Microsoft.AspNet.WebApi.Cors.

如果我将我的Web api控制器(dealscontroller)重命名为其他名称,则它工作正常.

If i am renaming My web api controller (dealscontroller) to some other name, it is working fine.

但是我不明白这里到底发生了什么以及fluentvalidation.webapi更新可能在我的解决方案和其他api中带来什么其他风险.

But i don't understand what is exactly happening here and what other risk this update of fluentvalidation.webapi can have in my solution and other apis.

推荐答案

我认为,当您安装FluentValidation.WebAPI时,它是在升级Microsoft.AspNet.WebApi或其他Web API库(尽管这不应该发生).如果不是,则此Microsoft.AspNet.WebApi.Cors肯定会更改版本(如果您未使用最新版本).

I think when you are installing FluentValidation.WebAPI it is upgrading the Microsoft.AspNet.WebApi or other Web API libraries (although that shouldn't happen). If not this Microsoft.AspNet.WebApi.Cors will definitely change the version (if you are not on the latest version).

因此,您需要确保MVC项目和类库中的Web API库版本相同.

So you need to make sure the version of Web API libraries is same in both MVC project and class library.

这篇关于安装fluentvalidation.webapi后无法命中重复的控制器路线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆