我检查了与mvc5,webapi2相关的链接,但无法弄清楚我的错误。
我的问题: / api / EBanking / CheckLogin没有在ebankingcontroller中删除checkLogin方法的代码
检查链接:
Custom Routing not working in MVC5
QueryString with MVC 5 AttributeRouting in Web API 2
App_start代码:
df['x']=np.min(df['x']+1,4)
RouteConfig.cs
df['x']=df['x']+1
df[df['x']>4]['x']=4
WebApiConfig.cs
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
AutoMapperCentralAppConfig.Configure();
}
APi控制器:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
答案 0 :(得分:1)
在您的WebApiConfig.cs中添加另一条基于行动的路由路由,如下所示:
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "ActionBased",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "Default",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
此"api/{controller}/{action}/{id}"
将允许调用api / ebanking / checklogin
或者,您甚至可以在属性中添加完整路线,例如:
[Route("api/EBanking/CheckLogin")]
public IEnumerable<usr06user_role> CheckLogin(string UserName, string Password)
{
//main code which doesn;t runs
}