简体   繁体   English

用户注册(site.com/name)并防止路径冲突

[英]User signup (site.com/name) and preventing against path clash

Not sure how best to word this, but let's say you have a site that allows users to have a profile at the root level of the app's path: 不确定如何最好地表达这种说法,但是假设您有一个网站,该网站允许用户在应用程序路径的根目录下拥有个人资料:

http://www.example.com/ http://www.example.com/

...and let's say the site has certain root level pages: ...并且假设该网站具有某些根目录页面:

/about /关于
/privacy-policy /隐私政策
/contact /联系
/terms-of-use/ /使用条款/
etc. 等等

What's the best way to prevent users from creating usernames that clash with those paths, and what's the best way to setup the routing for this? 阻止用户创建与这些路径冲突的用户名的最佳方法是什么,以及为此设置路由的最佳方法是什么? The default routing in MVC will handle your typical controller/action/id layout. MVC中的默认路由将处理您的典型控制器/动作/ ID布局。 So, I'm guessing it should hit the specifics first, and then check against the profiles. 因此,我想它应该先打细节,然后再检查配置文件。 How to best accomplish this? 如何最好地做到这一点?

Thanks all! 谢谢大家!

There are various ways to approach this. 有多种方法可以解决此问题。 One is to use HandleUnknownAction for the profiles. 一种是将HandleUnknownAction用于配置文件。 You can also use reflection to get the list of non-profile actions. 您还可以使用反射来获取非配置文件操作的列表。

Simply request the route for a uri based on the username. 只需根据用户名为uri请求路线即可。 Phil Haack I believe has code to unit test routes based on a uri. 我相信Phil Haack具有基于uri对单元测试路线进行编码的代码。 I have some code for that I will edit after I get back if you don't see it on his blog. 如果您在他的博客上看不到该代码,那么我有一些代码可供编辑。

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

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