我正在使用属性路由。我为行动ex:contactimage分配了路线值。有时我收到客户端的请求,例如'.../contact image'
,'.../co ntactimage'
等。我想替换URL中的空格并为其分配操作。我该怎么办?
编辑1:我扩展了ControllerFactory
- 创建控制器方法。我对该方法中的路由值进行了更改并调用base.CreateController
。仍然系统抛出错误。
public override IController CreateController(System.Web.Routing.RequestContext requestContext, string controllerName)
{
string controllername = requestContext.RouteData.Values["controller"].ToString();
if (controllername.Replace(" ","").ToLower()== "campaignimage")
{
requestContext.RouteData.Values["controller"] = "Campaign";
requestContext.RouteData.Values["action"] = "CampaignTrackerImage";
controllerName = controllerName.Replace(" ","");
}
return base.CreateController(requestContext, controllerName);
}