如何更改asp.net网页API默认路由

编程入门 行业动态 更新时间:2024-10-25 23:24:32
本文介绍了如何更改asp网页API默认路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我工作的asp网页API。我想设置为我的项目的默认路由在Global.asax文件一样,

I am working on asp web api. I am trying to set the default route for my project in global.asax file like,

localhost:45678/api/Products

但我没有找到像

url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }

它总是重定向我主页(HomeController中)。请指导我。

It always redirects me to Home page(HomeController). please guide me.

推荐答案

检查你的 RouteConfig 类在 App_Start 文件夹中。您应该看到的默认路由下面,你可以改变。

Check your your RouteConfig class in your App_Start folder. You should see the default route below which you can change.

routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } );

修改

阅读您的意见后,我觉得这个问题是不是与你的路由。我不知道你为什么会的希望的去做,但你只需要指定起始网址为您的项目。右键单击您的Web项目 - 点击属性 - 点击网络标签 - 在开始行动选择开始网址,然后输入 HTTP ://本地主机:45678 / API /产品在框中。保存项目并再次运行。它应该在新的位置开始。

After reading your comments, I think the problem is not with your routes. I'm not sure why you would want to do it, but you just need to specify the Start URL for your project. Right click your web project - click Properties - click the Web tab - under Start Action select Start URL and enter localhost:45678/api/Products in the box. Save your project and run again. It should start at the new location.

更多推荐

如何更改asp.net网页API默认路由

本文发布于:2023-11-14 13:28:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1587341.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由   如何更改   网页   net   asp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!