I want to have an endpoint that looks like: localhost:5000/abc123
This is basically to replicate the functionality of tinyurl.
Controller
[HttpGet("/{myString}")]
public async Task<IActionResult> Get(string myString)
{}
This works but all files now come through this contoller eg: localhost:5000/runtime.js etc
Is this possible to do only for certain strings?
Use Route constraint to filter values for myString
For example, if a file name is a string containing a dot .
is a valid suggestion in your case, you can use the following regex
to accept alphanumeric strings
[HttpGet("/{myString::regex(^\\w+$)}")]