I have a blog at domaintest.com/blog
And I want to have only the first level path map to a request. For example:
domaintest.com/blog/blog-post-title and not domaintest.com/blog/blog-post-title/ANYTHINGAFTER
I know how to get a HTTPGet request but how would I get the request value of the path?
CodePudding user response:
Razor Pages routing is based on file location. By default, the final segment in the URL must match the name of a file, or a folder with an Index.cshtml
file in it. Any intervening segments represent folders rooted in the Pages folder. A request for domaintest.com/blog/blog-post-title/ANYTHINGAFTER
would only match if you have a folder and file structure like this:
Pages
Blog
blog-post-title
ANYTHINGAFTER.cshtml <-- match on file name
ANYTHINGAFTER
Index.cshtml <-- match on folder name with index.cshtml in it
If you don't have a folder named blog-post-title, the URL will not match and the middleware will return a 404 Not Found. So your stated requirement is satisfied by existing behaviour.
On to your actual question, if you want the path of a request, use Request.Path
.