© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•15mo ago•
19 replies
Luca | LeCarbonator

✅ Is it possible to access a Controller's URI at runtime?

I'm not well versed in MVC structures, so this very well could be a XY problem. Let me know if it is a bad idea to begin with.

I'm trying to create a GET endpoint for
/collections
/collections
which returns Collections. One
Collection
Collection
always contains a nested Model
User
User
.

On its own, this is not a problem. However, I am creating my API based around
application/hal+json
application/hal+json
, which requires Resources to have a link to point to their exact location.

So when accessing a returned
Collection
Collection
, I could use its related link if I wish to access it directly instead.
It looks sort of like this:

Endpoints:
/collections
/collections

/collections/{uuid}
/collections/{uuid}


{
  "_links": {
    "self": {
      "href": "http://foo-api/collections"
    }
  },
  "_embedded": {
    "collection": [

      {
        "fooProp": "I'm a specific collection",
        "_links": {
          "self": {
            "href": "http://foo-api/collections/62fcac86a39a11ef"
          }
        }
      }

    ]
  }
}
{
  "_links": {
    "self": {
      "href": "http://foo-api/collections"
    }
  },
  "_embedded": {
    "collection": [

      {
        "fooProp": "I'm a specific collection",
        "_links": {
          "self": {
            "href": "http://foo-api/collections/62fcac86a39a11ef"
          }
        }
      }

    ]
  }
}


This is all well and good, but I have some concerns with generating the embedded collection's link.
If I hardcode it as
$"http://foo-api/collections/{uuid}"
$"http://foo-api/collections/{uuid}"
, then I would have to change the domain in every location where I did it.

Is it possible to access the
CollectionController#GetById(string uuid)
CollectionController#GetById(string uuid)
somehow and extract its URI at runtime?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Is it possible to access windows objects in a static method?
C#CC# / help
3y ago
✅ Is it possible to Parse a string and identify it's type?
C#CC# / help
17mo ago
✅ Access a runtime Dictionary easier
C#CC# / help
17mo ago
Trying to compile a script at runtime
C#CC# / help
3y ago