asp.net mvc5 路由配置http://localhost//video/{uuid}/{file}.{type}
时间: 2023-08-24 13:14:04 浏览: 98
对于你提供的 URL 模式 `http://localhost/video/{uuid}/{file}.{type}`,你可以通过 ASP.NET MVC5 的路由配置来实现。
首先,在 `RouteConfig.cs` 文件中进行路由配置。你可以使用以下代码来添加一个自定义的路由规则:
```csharp
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "VideoRoute",
url: "video/{uuid}/{file}.{type}",
defaults: new { controller = "Video", action = "Play" }
);
// 其他路由配置...
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
```
在上述代码中,我们添加了一个名为 "VideoRoute" 的路由规则,它匹配了 `video/{uuid}/{file}.{type}` 这样的 URL,并将请求发送到 `VideoController` 的 `Play` 方法。
接下来,在控制器中创建一个名为 `VideoController` 的控制器,并在其中添加一个名为 `Play` 的方法:
```csharp
public class VideoController : Controller
{
public ActionResult Play(string uuid, string file, string type)
{
// 在这里处理视频播放逻辑,可以使用 uuid、file 和 type 参数
return View();
}
}
```
在上述代码中,我们在 `VideoController` 中创建了一个名为 `Play` 的方法,并将 `uuid`、`file` 和 `type` 作为参数。你可以在此方法中处理视频播放逻辑,并使用这些参数。
现在,当你访问类似于 `http://localhost/video/12345678/video.mp4` 的 URL 时,它将匹配到 `VideoController` 的 `Play` 方法,并将参数 `uuid` 设置为 `12345678`,参数 `file` 设置为 `video`,参数 `type` 设置为 `mp4`。
请确保在路由配置时将自定义的路由规则放在一般规则之前,以确保正确匹配。
阅读全文
相关推荐


















