简体   繁体   English

是否可以有一个指向两个不同页面的URL?

[英]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. 您可以通过几种方法执行此操作。

  • Javascript 使用Javascript
  • Model View Controller (Controller) 模型视图控制器(控制器)
  • ASP.NET Web-Forms (Method) ASP.NET Web窗体(方法)

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.

相关问题 一个应用程序可能有两个notifyicons吗? - Is it possible for a single app to have two notifyicons? 单个应用程序可以有两个.master页面吗? - Can we have two .master pages for single application? 一个UserControl中可以有两个不同的DataContext吗? - Is it possible to have two different DataContext in one UserControl? 如何使一个路由指向两个不同的控制器端点,该端点在WEB Api 2中接受不同的参数 - How to have a Route which points to two different controller end points which accepts different arguments in WEB Api 2 单个 ServiceManifest.xml 文件是否可以有两个“ServiceManifests” - Is it possible to have two "ServiceManifests" for a single ServiceManifest.xml file 是否可以在.NET中具有两个不同名称的相同属性 - Is it possible to have same property with two different names in .NET 是否可以在一个带有 NPOI 的单元格中拥有两个不同的 colors 文本? - Is it possible to have two different colors of text in one cell with NPOI? 如何在单个 mrt 文件中的不同页面上拥有多个业务对象并在 C# WinForm 中显示它 - How can I have multiple Business Objects on different pages in a single mrt file and display it in C# WinForm 是否可以在两个不同的服务器上托管的已执行的单个WCF服务连接到相同的单个数据库 - Is it possible to Executed single WCF service hosted on two different Servers Connecting to same single DB 两个不同的类是否有可能具有一个属性 - 一个类的集合,并且每个 object 都知道它属于前两个类中的哪一个? - Is it possible that two different classes have a property -a collection of classes and each object knows which of the first two classes it belongs to?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM