haacked / feedback

Ask @haacked anything!
7 stars 1 forks source link

Url.RouteUrl returns null #208

Closed yaddly closed 4 years ago

yaddly commented 4 years ago

Good day Marius, I trust this note find you well. I'm Admire Mhlaba from South Africa, sorry to bother you but I came across https://haacked.com/archive/2011/02/20/routing-regression-with-two-consecutive-optional-url-parameters.aspx/ article teaching about routes. I have recently noticed something strange with Url.RouteUrl method, it always returns null when I pass a route name used in my attribute routing.

I have this :

[AllowAnonymous, HttpGet("confirm-account-email/{userId:alpha?}/{code:alpha?}", Name = "confirm_account_email")] public async Task ConfirmEmail(string userId = null, string code = null) { //code here }

When I try to do this, callback is always null and I'm lost and would appreciate any help you can afford me.

string callback = Url.RouteUrl("confirm_account_email", new { userId = "user-id-value", code = "token-value" }, Request.Scheme);

Thank you for reading through, looking forward to read from you anon.