If I'm using Attribute Routing in an ASP.NET controller, are those path templates considered hard coded? For instance, if I add [HttpGet("/employee")] or [Route("/employee")], is the /employee path a hard-coded value?
Are path templates defined using Attribute Routing considered hard coded?
469 Views Asked by Shubham Tiwari At
1
There are 1 best solutions below
Related Questions in C#
- Passing arguments to main in C using Eclipse
- kernel module does not print packet info
- error C2016 (C requires that a struct or union has at least one member) and structs typedefs
- Drawing with ncurses, sockets and fork
- How to catch delay-import dll errors (missing dll or symbol) in MinGW(-w64)?
- Configured TTL for A record(s) backing CNAME records
- Allocating memory for pointers inside structures in functions
- Finding articulation point of undirected graph by DFS
- C first fgets() is being skipped while the second runs
- C std library don't appear to be linked in object file
- gcc static library compilation
- How to do a case-insensitive string comparison?
- C programming: Create and write 2D array of files as function
- How to read a file then store to array and then print?
- Function timeouts in C and thread
Related Questions in ASP.NET-CORE
- ASP.NET 5 Class Library - Nuget package Web.Config transform
- Asp.Net 5 correct way to access logging config file from Startup.cs
- What is the difference between 'dependencies' and 'frameworkAssemblies' in project.json?
- Getting absolute URLs using ASP.NET Core
- How to add Project Reference in asp.net 5 application
- Configure the authorization server endpoint
- Observer for fire&forget Task
- IApplicationBuilder exists in both Microsoft.AspNet.Http.Abstractions and Microsoft.AspNet.Http
- What frameworks are available in ASP.NET Core (ASP.NET 5) applications?
- How do I include 'System.Runtime.Serialization.Json' namespace in my VSCode project on Mac OS X?
- How to suppress warnings when building an ASP.NET 5 project?
- Dependency Injection in asp.net 5 custom classes, what is the correct way?
- How to access IConfiguration property from Controller in ASP.NET 5
- Getting a scoped component from a IDocumentStoreListener
- How is execution passed from the clr to Startup class (startup.cs)?
Related Questions in CODING-STYLE
- Best practices for creating a huge SQL table
- Is there a nicer way to do this?
- Does Elixir have coding standards or an authoritative style guide published by the language developers, like PEP8 or the Erlang Programming Rules?
- Nesting anonymous delegates in C# - how to make code maintainable and readable?
- Converting data structures to other data structures
- Node.js and Q Promises: How can I hand over parameters in a cleaner way?
- What is the meaning of int[]
- Where are line breaks allowed within Haskell expressions?
- VIM - Reformatting indentation and braces
- How can I define a subprocess in the __init__() part in Python?
- How to insert values in STL map within a loop
- Java abstract method: is this bad practice?
- How to use constant powers of 2 readable in c++?
- Good practice to explicitly declare variables without 'much' use in favor of readability?
- Order of functions within a Python source file
Related Questions in ASP.NET-CORE-ROUTING
- Routing in MVC 6
- Get element based on string
- How to write a middleware as custom router in asp.net core?
- InvalidOperationException: The view 'ViewName' was not found after adding route
- asp.net core route handle id after domain
- Setting up routes in ASP.NET Core 3 MVC web app
- How do I solve the 'View not found' error in ASP.NET Core MVC in areas?
- How to combine route name with route parameters
- Can't get HTTP PUT request to work in ASP.NET Core
- How to assign multiple MVC routes to one method and determine the used route?
- OData dynamic per-request EDM creation and endpoint routing in ASP.NET Core 3.1+
- Adding [Authorize] to controller failing to redirect to Identity Login route. ASP.NET CORE 3.1 MVC
- .NET Core 2.1 adds area as url parameter
- Redirect to same page with an extra parameter
- How to create a Net Core Middleware to validate a route parameter
Related Questions in HARD-CODING
- Simple hard coded ListView in Android
- SQL Server: avoiding hard coding of database name in cross-database views
- SymmetricDS Community Edition passwords hard-coding in property files
- I want to hardcode the value of a dummy column from my view created upon an oracle DB
- hardcoded ID vs query
- How to remove non-breaking spaces from HTML hard coding
- Java: Using key names from properties file without using hardcoded strings as keys
- Index 12 out of bounds for length 12. How can I fix this problem?
- Create DB by taking DBName from C# application
- How to avoid hardcoding text files in java
- Are hard-coded STRINGS ever acceptable?
- How do I create an html report without hardcoding the html?
- How to remove hard coding of Exe names in C++ application?
- External file for strings, as opposed to hardcoding them
- Hard coding in IOS app
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
As others have noted in the comments, these routes are definitely hard-coded—but that may not be a real concern. It would be useful to better understand what requirements are driving this concern, as the solution will ultimately depend on that. In the meanwhile, I can provide some high-level guidance based on common scenarios.
Single Tier Web Application
If your controllers are distributed as part of your web application, and your routes are always defined at design time (i.e., as part of your development process), then it's just a stylistic preference as to whether your route paths are hard-coded as part of your controllers or hard-coded as part of your
Startupclass. This is the typical scenario for most web applications.Distributable Class Library
If you're distributing your controllers as part of a Class Library (or a Razor Class Library) which is intended to be used on multiple web applications, then this is a bigger consideration. In that scenario, hard-coding the routes as part of your controller prevents consumers of your class library from modifying the paths.
This could be advantageous if you want to ensure the same routes are always used while simultaneously eliminating the need to configure them on a per-application basis. But it may instead make sense to allow each application to customize these routes in their
Startupclass, thus giving consumers flexibility to customize where your library's endpoints live. If that's the case, hard-coding these values in your class library's controllers is undesirable.Dynamic Route Configuration
Another scenario where hard-coding the routes may be a concern is if, for some reason, you need them to be dynamically configured at run-time and/or are using configuration values from an external data source.
For example, if you're building a platform as a service (PAAS), it's sometimes desirable to provide a web interface where users can configure routes associated with particular services, and then have those dynamically registered, instead of hard-coding them into the platform itself. That's a far more involved approach, though.