[英]Is it possible to have a single URL that points to two different pages?
I have one url (/settings) that needs to point to two different pages depending on the users security on login. 我有一个网址(/ settings),它需要指向两个不同的页面,具体取决于登录时用户的安全性。 One page is the existing webforms page the other is a new MVC page.
一个页面是现有的Webforms页面,另一个是新的MVC页面。 Is this even possible?
这有可能吗?
Additional Info: When the user is on either page the url needs to say website.com/settings 附加信息:当用户在任一页面上时,URL都需要说“ sites.com/settings”
Solution: Convinced the PM to change the requirements. 解决方案:说服PM更改要求。
This is a redirects based approach. 这是基于重定向的方法。 Create a web page mapped to
/settings
, and have this code run on page load. 创建一个映射到
/settings
的网页,并使此代码在页面加载时运行。
if(User.IsAdministrator()) //I take it you have some way of determining who is an Admin, so this is just example code
{
Response.Redirect("~/AdminSettings.aspx");
}
else
{
Response.Redirect("~/UserSettings.aspx");
}
Note that you'll need security on the Admin page to make sure a regular user can't just navigate directly there. 请注意,您将需要在“管理”页面上获得安全性,以确保普通用户不能仅直接浏览该页面。
The short answer, yes . 简短的答案是 。 You can do this several ways.
您可以通过几种方法执行此操作。
It is often poor practice to do such an event, as it can expose data. 进行此类事件通常是不明智的做法,因为它可能会暴露数据。 It is indeed possible:
确实有可能:
Javascript: 使用Javascript:
$(document).ready(function () {
if($("#Account").val() != '') {
$(".Url").attr('href', 'http://www.google.com');
}
});
Pretend #Account
is a hidden field that is populated from your database. 假装
#Account
是从数据库填充的隐藏字段。 If the field is not null then modify the .Url
element to navigate to link. 如果该字段不为 null,则修改
.Url
元素以导航到链接。 That approach for Web-Forms is the most simple. Web窗体的这种方法是最简单的。
Web-Forms : 网络表格 :
protected void btnAccount_Click(object sender, EventArgs e)
{
if(User.IsInRole("Account"))
Response.Redirect("~/Admin.aspx");
else
Response.Redirect("~/User.aspx");
}
That would use the default Windows Authentication for the domain, you could bend and contort to use the database to pull data. 这将对域使用默认的Windows身份验证,您可以弯曲并扭曲以使用数据库提取数据。 An example, the Model View Controller would be similar as the
Controller
will simply handle that capability. 例如, 模型视图控制器将类似于
Controller
将仅处理该功能的情况。
Hope this points in right direction. 希望这指向正确的方向。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.