【问题标题】:restrict access to the users限制对用户的访问
【发布时间】:2014-06-21 18:43:06
【问题描述】:

我允许我的 Intranet 用户加载任何 HTML 页面。 用户只能加载以其用户名开头的 html 页面,例如:

User: 972547J 
Pages: 972537J*****.HTML

我使用了 asp.NET 和 VB.net,我只使用带有 972537J****.HTML 的页面的链接按钮创建了一个网格视图(对于这个用户)

那些页面是保密的,那么我不希望用户手动更改链接并显示其他用户的 HTML 页面。

我可以拒绝用户不打开其他人的html页面吗?使用 web 配置设置或 iis7 配置? HTML 页面不可编辑

【问题讨论】:

  • 您只显示可以访问的用户的链接而不是显示其他人的链接,您可以在linkbuttongridview后面显示您的代码,您如何填写gridview以及您如何管理显示linkbutton??

标签: asp.net vb.net


【解决方案1】:

第一步是使用asp.net设置IIS to handle.html文件

第二步是使用global.asax与用户登录检查文件名是否允许查看。

这里是一个简单的代码开始,属于global.asax

protected void Application_BeginRequest(Object sender, EventArgs e) 
{
    // you may need this
    HttpApplication app = (HttpApplication)sender;

    // start by check if is html file
    string cTheFile = HttpContext.Current.Request.Path;
    string sExtentionOfThisFile = System.IO.Path.GetExtension(cTheFile);

    if (sExtentionOfThisFile.Equals(".html", StringComparison.InvariantCultureIgnoreCase))
    {
        // check if the user is logged in
        if(  HttpContext.Current.User == null || 
             HttpContext.Current.User.Identity == null || 
            !HttpContext.Current.User.Identity.IsAuthenticated)
          )
        {
            // redirect him where you like
        }
        else
        {
            // make the rest test here
            // HttpContext.Current.User.Identity
        }
    }
}

处理程序参考:
Using ASP.NET routing to serve static files
ASP.NET MVC Routing - add .html extension to routes
http://technet.microsoft.com/en-us/library/cc770990(v=ws.10).aspx

【讨论】:

    猜你喜欢
    • 2017-08-11
    • 1970-01-01
    • 1970-01-01
    • 2019-06-09
    • 2015-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-18
    相关资源
    最近更新 更多