C
C#13mo ago
reeeeeee

❔ Remove Index from URL

How do I remove "Index" from Url, so I can call /Home, /Users, etc, wihtout additional /index. (but obv be still redirected to "Index" method in controller. I found this snipped and added it to my startup
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller}/{action}/{id?}");
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller}/{action}/{id?}");
Well, the Index is still there, and all actions without "Index" are redirected to my Users/edit/{id} action..
14 Replies
jalepi
jalepi13mo ago
Without the rest of the code it's difficult to tell
reeeeeee
reeeeeee13mo ago
Which part would be helpful? Controllers?
jalepi
jalepi13mo ago
Controller, yes
reeeeeee
reeeeeee13mo ago
Home
public async Task<IActionResult> Index()
{
_logger.Info("Index was clicked!");
return View();
}
Home
public async Task<IActionResult> Index()
{
_logger.Info("Index was clicked!");
return View();
}
User
[MvcAuthorize]
public async Task<IActionResult> Index(string search, int? page, int? pageSize)
{
... return View(model); }

[MvcAuthorize]
[HttpGet("{id}")]
public async Task<IActionResult> Edit(string id) {
... }
User
[MvcAuthorize]
public async Task<IActionResult> Index(string search, int? page, int? pageSize)
{
... return View(model); }

[MvcAuthorize]
[HttpGet("{id}")]
public async Task<IActionResult> Edit(string id) {
... }
Container
public async Task<IActionResult> Index() {....}
Container
public async Task<IActionResult> Index() {....}
Should I specify [Route] for each method?
jalepi
jalepi13mo ago
You definitely can, but easier should be mapping a route without {action} or setting it as default equals to Index.
reeeeeee
reeeeeee13mo ago
But this be something like:
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller}/{action=Index}/{id?}"
);
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller}/{action=Index}/{id?}"
);
The localhost/ shows like /Home/Index the /Home shows like /User/Edit The /Container shows like /User/Edit I dont get it .. hm, could this be an issue with my Users.Edit?
[MvcAuthorize]
[HttpGet("{id}")]
public async Task<IActionResult> Edit(string id) {
[MvcAuthorize]
[HttpGet("{id}")]
public async Task<IActionResult> Edit(string id) {
jalepi
jalepi13mo ago
Try commenting it out and see what happens
reeeeeee
reeeeeee13mo ago
Yeah, if I remove it everything works fine hmm
jalepi
jalepi13mo ago
There is something wrong with edit's httpget attribute. I don't think is necessary. Try using just [HttpGet] instead, since {id} is set in defaul route...
reeeeeee
reeeeeee13mo ago
yeah i removed the [httpGet ] and it works fine, gonna keep it like this for now
jalepi
jalepi13mo ago
It is apparently adding a new route
reeeeeee
reeeeeee13mo ago
thanks for your help 😄 yeah i guess it matched too many routes
jalepi
jalepi13mo ago
rubberduck everything is going there 😂
Accord
Accord13mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts
❔ I'm trying to implement this networking project, but not sure how to do it?I'm asked to import data from a text file, convert these data and send it to a program called centra✅ Toolbox option not visible in visual studio 2023 while using winforms.So, I was trying to make a winforms project and I got to the step where I am supposed to Add Control❔ event handler not being triggeredI'm having difficulty making this event works, can someone more experienced point me what im doing ❔ Is it possible to create a augment reality system in windows form in visual studio.I have looked on stack overflow and other resources to try to find out if it is possible to make a a❔ I want to only have hours, minutes, secs, on my count up for my music:here code: ```c private async Task UpdateSongPositionAndDuration(string accessToken) { ❔ I wrote a program that calculates the shortest path to move fridge to a certain place but its slowI wrote a program that calculates the shortest path to move fridge to a certain place but the runtim❔ Razor pages - Filtering data (shown in table) by some random filtersAs mentioned in title, I am showing some data in table, and I need some filters, like `serialNumberWpf RichTextBox stylingGuys any idea how to disable automatic styling in WPF richtextbox For example i have toggle button ❔ Just beginning the stuffI found that c# is what I need basically, because I can do a lot of funny stuff with it. I need to kThis project is not supported in C# Dev Kit.I've problem when load my project in vscode. i want to change code from Microsoft Visual Studio to V