请在下面查看我的要求。
我想将用户重定向到具有以下条件的帐户/登录页面。
- 如果用户输入例如http://example.com/Customer1
customer1 是客户,我将其保存在一个配置表中,其中我有 customer1 的连接字符串
所以基本上 customer1 我需要检查这是否存在于数据库中,然后重定向到 /Customer1/account/login 页面。
请让我知道这是否可能?如果是,我如何设置或检查这个 map.route?
public ActionResult Login()
{
string CurrentURL = Request.Url.AbsoluteUri;
var subdomain = CurrentURL.Split('/')[5];
var getDB = (from c in dbcontext.Configuration
where c.CustomerName == subdomain
select new
{
DBName = c.CustomerDBName,
DBUserName = c.CustomerDBUserName,
DBPassword = c.CustomerDBPassword,
DBDataSource = c.CustomerDBDataSource,
DBConnectionString = c.CustomerDBConnectionStringName
}).FirstOrDefault();
dbcontext.ChangeDatabase(initialCatalog: getDB.DBName,
userId: getDB.DBUserName,
password: getDB.DBPassword,
dataSource: getDB.DBDataSource,
configConnectionStringName: getDB.DBConnectionString);
return View();
}
在上面的代码中,我只是检查用户输入的子域是否是 macthing,然后更改 EDMX 连接,但现在如何重定向到登录页面客户名称。
客户1/帐户/登录