Skip to content

odata 7.4.0 endpoints routing break when using route constraints #2134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
keatkeat87 opened this issue Apr 22, 2020 · 3 comments
Open

odata 7.4.0 endpoints routing break when using route constraints #2134

keatkeat87 opened this issue Apr 22, 2020 · 3 comments

Comments

@keatkeat87
Copy link

I m trying to use odata controller and razor page in same application.
my razor page have this config

public void ConfigureServices(IServiceCollection services)
{
    services.AddControllers();
    services.AddRazorPages().AddRazorPagesOptions(options =>
    {
        options.Conventions.AddPageRoute("/Index", "/{amp:regex(amp)}/{language:regex(zhHans)}");
    });
    services.AddOData();
}

it mean that when user visit path /amp/zhHans it will access Index.cshtml
the constraints regex will make sure only string "amp" and "zhHans" is available for this route match.

but after i add the config. the odata routing is broke to 404 not found.
if i remove the constraints and change it to
options.Conventions.AddPageRoute("/Index", "/amp/zhHans");
odata will work fine. so I suspect this is a bug.

The package i used is

Reproduce steps

git clone https://github.com/keatkeat87/odata-route-constraint-issue.git
F5 run
visit /odata/WeatherForecast will 404

Expected result

will get odata result.

Actual result

404

@xuzhg
Copy link
Member

xuzhg commented Apr 22, 2020

Hi, @keatkeat87

So far, the endpoint Link generator in 7.4 is very naive and only handle the basic template, for example: "abc{temp}". your template /{amp:regex(amp)}/{language:regex(zhHans)} is too complex and so far it's not handled.

@xuzhg xuzhg added the feature label Apr 22, 2020
@keatkeat87
Copy link
Author

Hi xuzhg,
Thank for quick reply. I am not very clear about how odata routing works. My template is for razor page route, why does it affect my odata route?
My understanding is that we have a route list (razor page route + odata route), they will match in order, then even if my razor template route is above the odata routes, but because it will eventually not match due to regex, then in the end my odata route should work properly. Is my understanding wrong?
and any workaround or direction for me?

@xuzhg
Copy link
Member

xuzhg commented Apr 22, 2020

@keatkeat87

I spent some time to dig more. and I synced with .NET Core team.
It seems this is an issue in the asp.net core 3x. See dotnet/aspnetcore#20801
I don't have workaround yet, if it's not urgent, please wait for the ship of new .net core 3.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants