Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. ASP.NET MVC (via Core or older): Easy controller routing

ASP.NET MVC (via Core or older): Easy controller routing

Scheduled Pinned Locked Moved The Weird and The Wonderful
asp-netcsharpc++javaarchitecture
1 Posts 1 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    raddevus
    wrote on last edited by
    #1

    Background - Escape From Legacy Java We have a 20 yr old Java windows service and we are trying to replace it (in production env.) with a C# service. JNI (Java Native Interface) Ridiculous! You have to write a C wrapper to every C# method. Nope. The tooling itself is like a cheese-grater down your face. Has to be an easier way. There is! Write C# Methods : Place Them In WebAPI Here it is. Just write up a nice C# ASP.NET MVC app. 1. Write each (Java) replacement method in C# 2. Provide a Controller\Action route to each method 3. Call each one as needed from Java This will help us prove out that the C# code handles everything the same way as the Java. Now The Weird/Wonderful Attempting to fire up the ASP.NET MVC Controller which simply provides the C# version of each Java method. Routing Fail! I spin it up and try to do a simple get on the method. Fail! Routing is weird or something? What? What!?! Hack around. Search. Hack some more. "Whyn't it hitting the controller?" :confused: Here's the Weird/Wonderful I Promised In the Controller just add this little decorator to the Action (C# method) and it's available via Get.

    [HttpGet("GetTime")]
    public string GetTime()
    {
    return DateTime.Now.ToString("HH:mm:ss");
    }

    Now you can hit : http://localhost:5231/MyController/GetTime Easy-squeezy lemon peezy. Docs Though? Try finding the documentation on that for me. I found something similar but not quite this. At first I had : [HttpGet(Name="GetTime")] That would compile but doesn't work. It's not the Name value you have to pass in, it's the Template value. :confused: I shall be liberated from Java. :rolleyes:

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups