【发布时间】:2015-01-18 10:29:55
【问题描述】:
当我运行我的应用程序时,我会在地址栏中看到以下 URL。
http://Localhost/
应用默认路由,
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Login",
action = "Login", id = UrlParameter.Optional }
);
但我要设置的是,
当我运行我的应用程序时,我希望看到这样的 URL,
http://localhost/clientName/login (I want to display this fixed URL on start up of application)
假设此时用户显示在登录屏幕上。并在登录屏幕上方显示“ClientName”。
现在我的要求是,用户应该能够修改这个“ClientName”。
例如。如果用户输入 John 作为 clientName,则在登录屏幕上方应显示 John。
我希望我清楚自己的要求。
现在我可以动态获取 clientName。为此,我设置了以下路线。
routes.MapRoute("Customers", "{customer}", new { controller = "Login", action = "Login" }, null);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Login",
action = "Login", id = UrlParameter.Optional }
);
我的登录控制器,
public ActionResult Login(string returnUrl, string customer)
{
if(ClientExists(customer)) //Check against DB or list or any other variable
{
//Do some custom logic
}
ViewBag.ReturnUrl = returnUrl;
return View();
}
请点击此链接http://www.codeproject.com/Tips/825266/ASP-NET-MVC-Dynamic-Routing 获取更多参考。
有了这个,我在 Login actionMethod 的“returnUrl”参数中看不到任何值。
那么首先如何设置那个固定的 URL? second 如何从 URL 动态更改和获取 clientName(如果更改)?
【问题讨论】:
标签: c# asp.net-mvc asp.net-mvc-4 asp.net-mvc-routing