【发布时间】:2018-04-23 10:03:11
【问题描述】:
我有一个项目,其中 Web 表单应用程序中有一个控制器。
我的控制器叫 Token
public class TokenController : BaseTokenController
{
public override bool IsInherited => true;
}
这个控制器继承自 BaseTokenController
public abstract class BaseTokenController : ApiController
{
public abstract bool IsInherited { get; }
public virtual bool Post([FromBody]TokenValidateArgs args)
{
if (!IsInherited)
throw new Exception("Attempt to call base token controller not allowed");
return args.Validate();
}
public virtual string Get()
{
if (!IsInherited)
throw new Exception("Attempt to call base token controller not allowed");
return new Token()
}
}
在我的 global.asax 中,我有一个名为 Register 的方法:
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute("API default", "api/{controller}/{id}",
new { id = RouteParameter.Optional });
}
而在global.asax Application_Start 的第一行代码是
protected void Application_Start(object sender, EventArgs e)
{
Register(GlobalConfiguration.Configuration);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
我确实有这个工作,但是我随后与项目的主分支合并,它停止工作。我看不出有什么改变。
这是错误:
未找到与请求 URI 'https://localhost:44398/api/token' 匹配的 HTTP 资源。 未找到与名为“token”的控制器匹配的类型。
有没有其他人遇到过类似的问题并且知道如何解决这个问题。我已经阅读了其他线程并尝试通过在控制器上放置一个 RoutePrefix 来解决这个问题,在 global.asax 上移动执行顺序并直接调用 get() 方法
【问题讨论】:
标签: asp.net asp.net-web-api webforms controllers