1

I have a project where all paths are routed through the same /index page, however this directs images/css/js files through the same page. In the example below, I am wondering how would I exclude those resources (i.e. /images/, /js/, /css/*, etc) from being routed to the /index page?

services.AddRazorPages().AddRazorPagesOptions(options => {
    options.Conventions.AddPageRoute("/index", "{*url}");
});
2
  • this directs images/css/js files through the same page. Do you mean that all request(s) to static files are mapped to index page? Commented Dec 9, 2020 at 5:24
  • The example I showed works great for us. all our pages get routed through /index and the page content gets loaded based on the path. However, we do not want files that are not pages to be routed to /index. So I am wondering how to modify that to exclude certain paths, for example, any path that begins with "/images/" Commented Dec 9, 2020 at 13:38

1 Answer 1

1

Using this regex, I was able to route everything except if the path has "images/" and it seems to work:

options.Conventions.AddPageRoute("/Index", "{*url:regex(^(?!images/).*$)}");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.