2 years ago
#32923
Aduciicba
How could I get rid of excessive unexpected parameters in url request in ASP .NET MVC?
Let's say I have a route and controller as below:
public class MyController : BaseController
{
[HttpGet]
[System.Web.Mvc.Route("mycontroller/{foo}/{something}")]
public ActionResult GetBySeoUrl(string foo, string something, string msg= "")
{
/*do smth*/
return Content($"{foo}, {something}, {msg}");
}
}
And I have requests like
/mycontroller/abc/bcd
/mycontroller/abc/bcd?msg=sd
which work fine.
But it also works with requests like
/mycontroller/abc/bcd?p1=ss&p2=&p3=ss
/mycontroller/abc/bcd?msg=sd&p1=ss&p2=&p3=ss
by just ignoring those unexpected parameters and returning the same page.
It becomes a problem for indexing when search engine get the same content for different urls.
Comparing the actual request param list with expected param list in the filter for each action seems to me as a very inefficient solution.
So is there a way to detect such unnecessary parameters and redirect to the normal url?
/mycontroller/abc/bcd?p1=ss&p2=&p3=ss => /mycontroller/abc/bcd
c#
asp.net-mvc-5
0 Answers
Your Answer