简体   繁体   English

如何拥有个人资料网址,例如facebook。 (asp.net)

[英]How to have a profile url like facebook. (asp.net)

HI i am new to aspdotnet and want to ask how do I able to have a facebook like profile link for each of the registered user in the database. 嗨,我是aspdotnet的新手,我想问我如何为数据库中的每个注册用户提供一个类似facebook的个人资料链接。

example: 例:

https://www.facebook.com/james

As you can see after .com there is a unique name. 如您所见,.com之后有一个唯一的名称。 but my question: Is that name a folder or some kind of auto generated link?? 但我的问题是:该名称是文件夹还是某种自动生成的链接? How can I implement this kind of link for each of the registered user in my database? 如何为数据库中的每个注册用户实现这种链接?

well i can easy do it wit GET but I want to hide the id from the url. 好吧,我可以轻松完成GET,但是我想从网址中隐藏ID。

Take a look at your RouteConfig.cs file in your App_Start folder. 查看App_Start文件夹中的RouteConfig.cs文件。

The default route (www.facebook.com) is set to your HomeController.Index() method. 默认路由(www.facebook.com)设置为HomeController.Index()方法。 You can tell that by the "defaults" parameter. 您可以通过“默认值”参数来说明这一点。

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

In the example that you provided, "james" would be a string parameter for that Index method. 在您提供的示例中,“ james”将是该Index方法的字符串参数。 Obviously, the signature to the method would be: 显然,该方法的签名为:

public ActionResult Index(string id) {
    // Do stuff
}

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

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