2015-09-04 16 views
1

我需要的鏈接是這樣的格式http://localhost:32136/username/HomePage網址的用戶名重定向在asp.net

例如: - https://www.facebook.com/xxxyyyy

請建議我的鏈接如何構造URL。我已經配置的路由.config as

routes.MapRoute(
name: "Profile", 
    url: "{username}", 
    defaults: new { controller = "Account", action = "Profile" }, 
    constraints: new { username = "Vinoth" } 
); 
+0

哪個列表,你會使用?你可以把更多的代碼放在這裏嗎? –

+0

http:// localhost:32136/username /主頁 用戶名將是vinoth例如如何操作 –

+0

我認爲這是URL,您將從列表中獲取記錄? –

回答

2

試試看。

RouteConfig.cs

routes.MapRoute(
    name: "ProfileRoute", 
    url: "{username}/{action}", 
    defaults: new { controller = "Account", action = "Profile" }, 
); 

AccountController.cs

public ActionResult Profile(string username) 
{ 
    if(username != "Vinoth") 
     return HttpNotFound(); 
    return View(username); 
} 
+0

RouteConfig.cs routes.MapRoute( 名稱: 「ProfileRoute」, 網址: 「{用戶名}/{行動}」, 默認:新{控制器= 「戶口」 ,action =「Profile」} ); routes.MapRoute( 名: 「默認」, URL: 「{控制器}/{行動} /(編號)」, 的默認值:新{行動= 「索引」,ID = UrlParameter.Optional} ); 帳戶控制器在apicontroller 公共IHttpActionResult配置文件(字符串用戶名) { if(username!=「Vinoth」) return NotFound(); return ok(username); } –

+0

我已經在webapi控制器中創建了AccountController.cs ..很好地使用那個 –

+0

它不工作請幫助我排序這.. –