有没有办法在asp.net
中检索此类网址的IDhttp://www.someurl.com/country/ {COUNTRY_ID} /郊区/ {suburb_id}
如何使用HttpContextBase检索两个id?
答案 0 :(得分:1)
假设您正在使用.NET MVC,您可以通过一些路由配置来实现此目的。
在BundleConfig / Global.asax中:
routes.MapRoute(
"CountryAndSuburb",
"country/{country_id}/suburb/{suburb_id}",
new { controller = "Countries", action = "CountryAndSuburb" }
);
控制器:
public class Countries: Controller
{
// GET country/{country_id}/suburb/{suburb_id}
public ActionResult CountryAndSuburb(int country_id, int suburb_id)
{
return Content(country_id.ToString() + ":" + suburb_id.ToString());
}
}
您也可以考虑绑定到POCO模型并将表单数据或JSON提交。但是,在这种情况下,URL可能不是RESTful语义。