简体   繁体   中英

How do I pass a parameter with slash in a ServiceStack route?

My requirement is to pass a value, as a parameter, in a ServiceStack route which includes a slash like this ' SK-LOT-79-14/3/11' so I can fetch the records in my service.

Example route configuration:

[Route("/cims/qcHistoryByLot/{lotNumber}", "GET")]

Example lot number: SK-LOT-79-14/3/11

You simply need to add a * to the end of your route parameter.

[Route("/cims/qcHistoryByLot/{lotNumber*}", "GET")]
public class GetQcHistoryByLot
{
    public string LotNumber { get; set; }
}

Using the asterisk * acts as a wildcard and will capture anything after /cims/qcHistoryByLot/ into LotNumber . See wildcard paths in the routing documentation for more information.

This will work for routes where you are passing the slash in the last route parameter. If you require to pass a slash in a parameter that does not come last on the route, then you will need to handle encoding the value. See my other answer here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM