【问题标题】:Restrict access to path in the URL限制对 URL 中路径的访问
【发布时间】:2019-02-15 19:40:00
【问题描述】:

如果我有一个网址“http://somesite.com/root/folder/subdirectory/myfile.pdf” 如何确保用户可以访问完整 URL 以查看和下载 myfile.pdf,但无法访问“http://somesite.com/root”或“http://somesite.com/root/folder”或“http://somesite.com/root/folder/subdirectory”??

实现可以是 HTML、angular 6、reactjs 或任何此类框架。

【问题讨论】:

  • 在 IIS 中,您可以通过将 directoryBrowsing 设置为 false 来做到这一点
  • 谢谢...可以在客户端启用吗?只是想是否可能存在任何安全漏洞。
  • 不行,端点用户只能访问他知道绝对url的文件!例如,如果用户知道您有一个名为 test.pdf 的文件,并且该文件在此路径上可用:http://somesite.com/root/folder/subdirectory/test.pdf 那么他可以偶然访问它

标签: angular html reactjs react-router


【解决方案1】:

您可以定义一个为您获取 pdf 的路由。

http://somesite.com/root/folder/subdirectory/test.pdf

在此路由的组件中,您可以根据名称获取 pdf。

<Route exact path="/root/folder/subdirectory/test.pdf" component={PDFComponent } />

import pdf from './assets/pdf/test.pdf';

class PDFComponent extends Component {
render(){
return(
 <pdf /> 
 );
}
}

这样只会访问特定的 url。

【讨论】:

    猜你喜欢
    • 2016-03-20
    • 1970-01-01
    • 1970-01-01
    • 2016-10-19
    • 2014-02-05
    • 1970-01-01
    • 2020-01-15
    • 2019-07-10
    • 1970-01-01
    相关资源
    最近更新 更多