asp.net-core-routing

ASP.NET Core Routing works in VS IIS Express but not in IIS 10

╄→гoц情女王★ 提交于 2019-12-06 10:20:03
问题 I am developing ASP.NET Core web API. here I have a situation like I have to use multiple get functions which get data from SQL server DB. So for that, I'm doing custom attribute routes. below are my codes [Route("api/[controller]")] public class MeController : Controller { private readonly ITechRepository _tech; private readonly IPageOptions _page; public MeController(ITechRepository tech,IPageOptions page) { _tech = tech; _page = page; } [Route("getTech")] public IEnumerable<TechStack> Get(

Route Name for HttpGet attribute Name for base generic controller class in asp.net core 2

依然范特西╮ 提交于 2019-12-05 12:45:36
问题 I have a generic controller, which have several derived controller classes. but I cannot figure out how to handle the HttpGet's route name since it require constant. [HttpGet("{id}", Name ="should not hard coded here for derived class")] public virtual async Task<IActionResult> Get(int id) I need the route name because in my HttpPost function I want to return CreatedAtRoute() which require HttpGet's route name The route name cannot be hard coded because all the derived class need to have a

Route Name for HttpGet attribute Name for base generic controller class in asp.net core 2

人走茶凉 提交于 2019-12-03 23:34:57
I have a generic controller, which have several derived controller classes. but I cannot figure out how to handle the HttpGet's route name since it require constant. [HttpGet("{id}", Name ="should not hard coded here for derived class")] public virtual async Task<IActionResult> Get(int id) I need the route name because in my HttpPost function I want to return CreatedAtRoute() which require HttpGet's route name The route name cannot be hard coded because all the derived class need to have a different route name. here is the base controller public abstract class BaseController<TEntity, TContext>

Routing in MVC 6

我与影子孤独终老i 提交于 2019-12-01 04:58:31
问题 I have a super simple controller with 2 methods: public IActionResult Users(long id) { return Json(new { name = "Example User" }); } public IActionResult Users() { return Json(new { list = new List<User>() }); } One to select all users and the other to return all users. In web api 2 I could user the following route and everything worked fine: config.Routes.MapHttpRoute( name: "Users", routeTemplate: "v1/Users", defaults: new { action = "Users", controller = "Users" }, constraints: null,

ASP.Net Core Web API convention-based routing?

左心房为你撑大大i 提交于 2019-12-01 03:25:31
What am I missing that I'm greeted with a 404 for this controller? I really don't want to use attribute-based routing. I also don't want action to be part of any URIs. I'm using Visual Studio 2017 and .Net Core 1.1. TestController.cs using System; using Microsoft.AspNetCore.Mvc; namespace Foo.Controllers { public class TestController : Controller { public long Get() => DateTimeOffset.Now.ToUnixTimeSeconds(); } } Note that this works with a [Route("api/Test")] attribute. But I don't want to use attribute-based routing. And as soon as I take that attribute off, I get 404s. Startup.cs namespace

ASP.Net Core Web API convention-based routing?

北慕城南 提交于 2019-12-01 00:19:58
问题 What am I missing that I'm greeted with a 404 for this controller? I really don't want to use attribute-based routing. I also don't want action to be part of any URIs. I'm using Visual Studio 2017 and .Net Core 1.1. TestController.cs using System; using Microsoft.AspNetCore.Mvc; namespace Foo.Controllers { public class TestController : Controller { public long Get() => DateTimeOffset.Now.ToUnixTimeSeconds(); } } Note that this works with a [Route("api/Test")] attribute. But I don't want to

AmbiguousActionException: Multiple actions matched. The following actions matched route data and had all constraints satisfied

。_饼干妹妹 提交于 2019-11-29 09:11:51
I am creating a website using ASP.NET Core MVC. When I click on an action I get this error: AmbiguousActionException: Multiple actions matched. The following actions matched route data and had all constraints satisfied: Web.Controllers.ChangeEventsController.Create (Web) Web.Controllers.ProductsController.CreateChangeEvent (Web) This is how I defined my action in the index.cshtmlm for my ProductsController: <a asp-controller="ChangeEvents" asp-action="Create" asp-route-id="@item.Id">Create Change Event</a> Here is my routing: app.UseMvc(routes => { routes.MapRoute( name: "default", template: "

How to pass multiple parameters to a get method in ASP.NET Core

徘徊边缘 提交于 2019-11-28 16:37:51
How can I pass in multiple parameters to Get methods in an MVC 6 controller. For example I want to be able to have something like the following. [Route("api/[controller]")] public class PersonController : Controller { public string Get(int id) { } public string Get(string firstName, string lastName) { } public string Get(string firstName, string lastName, string address) { } } So I can query like. api/person?id=1 api/person?firstName=john&lastName=doe api/person?firstName=john&lastName=doe&address=streetA You also can use this: // GET api/user/firstname/lastname/address [HttpGet("{firstName}/

How to pass multiple parameters to a get method in ASP.NET Core

。_饼干妹妹 提交于 2019-11-28 15:28:41
问题 How can I pass in multiple parameters to Get methods in an MVC 6 controller. For example I want to be able to have something like the following. [Route("api/[controller]")] public class PersonController : Controller { public string Get(int id) { } public string Get(string firstName, string lastName) { } public string Get(string firstName, string lastName, string address) { } } So I can query like. api/person?id=1 api/person?firstName=john&lastName=doe api/person?firstName=john&lastName=doe

AmbiguousActionException: Multiple actions matched. The following actions matched route data and had all constraints satisfied

非 Y 不嫁゛ 提交于 2019-11-28 02:34:30
问题 I am creating a website using ASP.NET Core MVC. When I click on an action I get this error: AmbiguousActionException: Multiple actions matched. The following actions matched route data and had all constraints satisfied: Web.Controllers.ChangeEventsController.Create (Web) Web.Controllers.ProductsController.CreateChangeEvent (Web) This is how I defined my action in the index.cshtmlm for my ProductsController: <a asp-controller="ChangeEvents" asp-action="Create" asp-route-id="@item.Id">Create