routes.MapRoute(
name: "ip",
url: "{controller}/{action}/{id}",
defaults: new { controller = "ip", action = "ipSearch" },
constraints: new { id = @"\d{3}\.\d{3}" }
);
匹配http://localhost:13726/ip/ipSearch/100.100
为什么匹配不过去。
参数为什么不能有.
routes.MapRoute(
name: "ip",
url: "{controller}/{action}/{id}",
defaults: new { controller = "ip", action = "ipSearch" , id = @"\d{3}\.\d{3}"}
);
因为这个规则是正则匹配规则,
在正则里.是不能直接用的,要匹配.,需要[.]这样代表一个.
在web.config中加上如下配置:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"></modules>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>