简体   繁体   English

WEB API URL路由

[英]WEB API URL Routing

I want paths like this: 我想要这样的路径:

localhost:99/client/themes/plain/index.html?shop=mycoolshop

to appear as: 显示为:

localhost:99/client/mycoolshop/index.html.

I wrote: 我写:

  routes.MapPageRoute(
            routeName: "Client",
            routeUrl: "client/{shopname}/{page}",
            physicalFile: "~/client/themes/plain/{page}?Shop={shopname}"
       );

But to no luck. 但是,没有运气。 When I type localhost:99/client/mycoolshop/index.html it says page not found. 当我键入localhost:99/client/mycoolshop/index.html它说找不到页面。 What am I doing wrong? 我究竟做错了什么?

I think you may be looking for URL Rewriting rather than WebAPI routing. 我认为您可能正在寻找URL重写而不是WebAPI路由。 Take a look at this SO thread 看看这个SO线程

You can use this setting in the system.web section of your web.config: 您可以在web.config的system.web部分中使用此设置:

<httpRuntime relaxedUrlToFileSystemMapping="true" />

Here's a more detailed explanation of how this works. 这是有关其工作原理的详细说明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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