简体   繁体   English

创建动态虚拟目录,例如Facebook用户名

[英]Creating dynamic virtual directories like Facebook usernames

I want to add a functionality to my website that allows users to pick a username and then be able to access their page using www.thisismysite.com/theirusername I have searched all over google but im not really even sure what im looking for. 我想在我的网站上添加一个功能,允许用户选择用户名,然后能够使用www.thisismysite.com/theirusername访问我的整个Google网站,但我什至不确定自己在寻找什么。

I want the same functionality as facebook usernames for example http://www.facebook.com/jason.vearncombe 我想要与Facebook用户名相同的功能,例如http://www.facebook.com/jason.vearncombe

Anyone have any ideas? 有人有想法么?

BTW im using asp.net c# BTW即时通讯使用asp.net C#

You can do that easily with Attribute Routing in ASP.NET MVC 5 您可以使用ASP.NET MVC 5中的属性路由轻松做到这一点

http://blogs.msdn.com/b/webdev/archive/2013/10/17/attribute-routing-in-asp-net-mvc-5.aspx#optionals-and-defaults http://blogs.msdn.com/b/webdev/archive/2013/10/17/attribute-routing-in-asp-net-mvc-5.aspx#optionals-and-defaults

In MVC, a url does not need to map to a file or a directory. 在MVC中,URL不需要映射到文件或目录。 A url can be mapped to a function, the parts of the url will then be the parameter of the function. 可以将url映射到函数,然后url的各个部分将成为函数的参数。 Such functions are called Action methods. 这种功能称为动作方法。 Mapping a url to an action is called Routing. 将URL映射到操作称为路由。 MVC framework allows you to define routes, then the framework will parse the url and does its magic to call your Action methods. MVC框架允许您定义路由,然后该框架将解析URL并发挥其魔力来调用您的Action方法。

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

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