ASP.Net MVC - handling bad URL parameters

前端 未结 5 1741
不知归路
不知归路 2021-02-01 07:21

What\'s the best way to handle a visitor constructing their own URL and replacing what we expect to be an ID with anything they like?

For example:

ASP.Net MVC -

5条回答
  •  别那么骄傲
    2021-02-01 08:06

    You can specify constraints as regular expressions or define custom constraints. Have a look at this blog post for more information:

    http://weblogs.asp.net/stephenwalther/archive/2008/08/06/asp-net-mvc-tip-30-create-custom-route-constraints.aspx

    You will still need to deal with the situation where id 43243 doesn't map to anything which could be dealt with as an IActionFilter or in your controller directly.

提交回复
热议问题