Recently encountered a disgusting problem:
Actions in testcontroller are as follows:
1 PublicActionresult index (Question)
2 {
3 ReturnView (question );
4 }
The question parameter is defined as follows:
1 Public Class Question
2 {
3 Public String Id { Get ; Set ;}
4 Public String Name { Get ; Set ;}
5 }
Then I use HTML. the href of the a tag generated by actionlink ("example", "Index", "test", new question {id = "12312312312", name = "asdfasdfasdf"}, null) is:
Http: //.../test/home/12312312312? Name = asdfasdfasdf
That is to say, it places the ID in the route by default (basically because we have the default route: {controller}/{action}/{ID }, the reason for the duplicate names of the IDS ). this book is nothing, because the server action can also be normally bound to parameters. however, what is abnormal is that my ID often contains "/" such
Html. actionlink ( " Example " , " Index " , " Test " , New Question {ID = " 123/123/123/12 " , Name = " Asdfasdfasdf " }, Null )
This lineCodeThe generated result is: http: //.../test/home/123/123/12312? Name = asdfasdfasdf is definitely an invalid URL. and even if I use the URL. after encode the value of ID, it seems to be correct: http: // localhost: 3427/test/index/123% 252f123% 252f12312? Name = asdfg but % 252f will change to/after arriving at the server and then match the action controller ID, so our ID value is still 123/123/12312. this issue is indeed quite tangled.
Solution:
(1): Since the default route contains the ID Section and the ID is placed in the route, we can start with the default route, we can change the ID in the default route to another one, for example, myid: {controller}/{action}/{myid}, or simply delete the {ID} segment. in fact, you can also force 123/123/12312 to match the ID in the form of {* ID}. However, this form is too broad and may easily affect other codes, I chose to delete the {ID} section directly.