ASP.NET MVC唯一的URL路由 [英] ASP.NET MVC unique url routing

查看:84
本文介绍了ASP.NET MVC唯一的URL路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我通读了有关MVC路由的教程和书籍,并在我的项目中使用了它,并对如何使用它来完成我想要的实现有了相当扎实的理解。

So, I've read through tutorials and books about MVC routing as well as played with it on my projects and come to a pretty solid understanding of how to use it to accomplish what I want to with it.

但是,我遇到的事情我还不太清楚。

But, I'm up against something I can't quite figure out yet.

我想要完成的是每个客户端的唯一网址(类似于 http://mysite.com/client/1)。该网址会将浏览器带到客户端控制器,索引操作,ClientId = 1 ...显然。

What I want to accomplish is a unique url for each client that doesn't look like "http://mysite.com/client/1". This url would take the browser to the Client Controller, Index action, ClientId = 1...obviously.

我想做的是使用类似 http://mysite.com/Acme,它将执行数据库查找以找出哪个客户端具有唯一的名称 Acme,然后将请求重定向到客户端控制器的索引视图,并将ClientId设置为任何名称

What I'd like to do is have a URL like "http://mysite.com/Acme" that would do a database lookup to figure out which client has the unique name of "Acme", and then redirect the request to the Client Controller, Index view and set the ClientId to whatever it is on the client with the name 'Acme'.

默认路由不断捕获并无法处理它。

The default route keeps catching it and can't handle it.

有什么想法吗?

推荐答案

我建议使用全局操作过滤器即可完成此操作,也可以创建带有静态路径的路由,该路由将路由到您的查找控制器(例如/ lookup / {companyname}将路由到您的数据库查找控制器。)

I recommend using an Global Action Filter to accomplish this or you can create a route with a static path that will route to your lookup controller (e.g., /lookup/{companyname} will route to your database lookup controller).

这篇关于ASP.NET MVC唯一的URL路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆