惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
Recent Commits to openclaw:main
Recent Commits to openclaw:main
H
Heimdal Security Blog
SecWiki News
SecWiki News
H
Hacker News: Front Page
N
News | PayPal Newsroom
L
LINUX DO - 最新话题
N
News and Events Feed by Topic
TaoSecurity Blog
TaoSecurity Blog
AI
AI
C
Cybersecurity and Infrastructure Security Agency CISA
Scott Helme
Scott Helme
PCI Perspectives
PCI Perspectives
S
Securelist
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Cyberwarzone
Cyberwarzone
A
Arctic Wolf
Forbes - Security
Forbes - Security
T
Tor Project blog
Spread Privacy
Spread Privacy
WordPress大学
WordPress大学
I
Intezer
Martin Fowler
Martin Fowler
Help Net Security
Help Net Security
P
Proofpoint News Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Cisco Talos Blog
Cisco Talos Blog
Latest news
Latest news
博客园 - 司徒正美
W
WeLiveSecurity
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
V
V2EX
P
Palo Alto Networks Blog
Google DeepMind News
Google DeepMind News
IT之家
IT之家
阮一峰的网络日志
阮一峰的网络日志
V
Vulnerabilities – Threatpost
Jina AI
Jina AI
S
Security Affairs
Hacker News - Newest:
Hacker News - Newest: "LLM"
Simon Willison's Weblog
Simon Willison's Weblog
Project Zero
Project Zero
T
Threatpost
P
Privacy International News Feed
人人都是产品经理
人人都是产品经理
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - Franky
Hugging Face - Blog
Hugging Face - Blog
Apple Machine Learning Research
Apple Machine Learning Research

博客园 - 阿福

TypeScript forms authentication failed the ticket supplied was invalid错误 (Windows Server 2008 + IIS 7.5) jQuery Mobile 1.1.1 RC1发布 HashSet<T> vs List<T> 不要用把无序GUID既作为主键又作为聚集索引 WCF Data Services 5.0 RTM发布 EF Power Tools Beta 2发布 Entity Framework 5性能方面的注意事项 jQuery Mobile 1.1.0 RC2发布 源码+幻灯片:学习HTML5/jQuery/ASP.NET MVC/EF Code First的绝佳资源Account at a Glance项目 使用Autofac在ASP.NET Web API上实现依赖注入 在Windows Azure上开发ASP.NET程序与在Windows Sever上有何不同 充分利用缓存来提高网站性能 ASP.NET MVC 4, ASP.NET Web API, ASP.NET Web Pages v2 (Razor)全部开源,并接受来自社区的贡献(contributions) EF5 beta2通过NuGet发布 Getting Started with HTML5 开发HTML5应用你需要了解的 WCF入门资源 jquery history plugin, url hash Run Tasks in an ASP.NET Application Domain ASP.NET 2.0: 生成Excel报表 VS 2008 hot-fix终于出来了 Images; How to create an HTTP handler to dynamically resize images and change quality. ASP.NET 2.0: Add build-in paging feature to repeater/为repeater添加内置分页功能 Tip/Trick ASP.NET 2.0: DropDownList DataBind ASP.NET 2.0: Forms Authentication Across domains Ajax类库、框架、工具包完全列表 怀旧啊 Search Box Checking All CheckBoxes in a GridView Efficient Data Paging and Sorting with ASP.NET 2.0 and SQL 2005 JavaScript Calendar Cool MSDN ASP.NET 2.0 GridView Control Article Do I have to cry for you Google无法访问 扯淡 狗*! Atlas Control Toolkit and Source Code for the Build-in Asp.Net 2.0 Providers Great New Advanced Article on ASP.NET 2.0 Master Pages ASP.NET 2.0:通过SqlDataSource绑定数据到普通控件 通过客户端扩展实现固定GridView表头功能 不使用ISAPI或IIS wildcard实现不带扩展名URL的转向 VS 2005 Web Application Project & Atlas Control Toolkit & CSS Control Adapter ASP.NET 2.0 Language Swithcer and Theme Swicher 多语言转换和多样式主题转换 How to use virtual path providers to dynamically load and compile content from virtual paths in 
ASP.NET 2.0: Site Maps
阿福 · 2010-01-01 · via 博客园 - 阿福

Asp.net主页链接了一篇文章 Creating Menu Based on Role,主要讲述了根据不同角色和授权,显示不同的menu。感觉其解决方法并不是很好,其实ASP.NET 2.0 的SiteMaps特性内置就有Site-Map Security Trimming功能,就是根据角色和授权,menu显示不同项,完全是基于配置的,不用编码,并不用像前篇文章实现的那样繁琐。

复述一下文章中的场景,假设网站中有2个角色:Administrators, Users。

Administrators可访问路径为

Admins-/AddUser.aspx

         /DeleteUser.aspx

         /ModifyUser.aspx

Users的可访问路径为

Users-/ShowDetail.aspx

        /ShowList.aspx

       /......

需要根据用户登录后角色的判断显示不同的menu。

实现方式:一,可以使用SiteMap的Multiple Site Maps功能(像文章中那样);二,也完全可以不用。

方式一:

web.sitemap文件如下配置
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
  <siteMapNode url="Default.aspx" title="Home"  description="Home">
    <siteMapNode siteMapFile="~/Navigation/Admin.sitemap" />
    <siteMapNode siteMapFile="~/Navigation/User.sitemap" />
  </siteMapNode>

Navigation目录下Admin.sitemap, User.sitemap分别为:

<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >

  <siteMapNode url="" title="AdminFunctions" roles="administrators">
    <siteMapNode url="~/Admin/AddUser.aspx" title="Add User" />
    <siteMapNode url="~/Admin/DeleteUser.aspx" title="Delete User" />
    <siteMapNode url="~/Admin/UpdateUser.aspx" title ="Update User"/>
  </siteMapNode>
</siteMap>

<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
 <siteMapNode url="" title="UserFunctions" roles="users">
    <siteMapNode url="Showmydetails.aspx" title="Show my details" />
    <siteMapNode url="Editmydetails.aspx" title="Edit my details" />
  </siteMapNode>
</siteMap>

注意红色的两行只是为了起分组的作用,并不对应实际的地址,所以url为空。

web.config中启用securith trimming:

    <siteMap defaultProvider="XmlSiteMapProvider" enabled="true">
      <providers>
        <add siteMapFile="web.sitemap" name="XmlSiteMapProvider" type="System.Web.XmlSiteMapProvider" securityTrimmingEnabled="true" />
      </providers>
    </siteMap>

其实以上配置做完后只要正确使用了navigation控件(treeview,menu等),就已经起到了根据不同角色、授权,显示不同menu的作用了。但是要实现真正的授权控制还学要在web.config中配置,如:

  <location path="Admin">
    <system.web>
      <authorization>
        <allow roles="administrators" />
        <deny users="*" />
      </authorization>
    </system.web>
  </location>。

方式二:

不使用Multiple Site Maps功能,简单说就是只是用一个web.sitemap文件就可以了,

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
  <siteMapNode url="Default.aspx" title="Home"  description="Home">
      <siteMapNode url="" title="AdminFunctions" roles="administrators">
        <siteMapNode url="~/Admin/AddUser.aspx" title="Add User" />
        <siteMapNode url="~/Admin/DeleteUser.aspx" title="Delete User" />
        <siteMapNode url="~/Admin/UpdateUser.aspx" title ="Update User"/>
    </siteMapNode>
     <siteMapNode url="" title="UserFunctions" roles="users">
       <siteMapNode url="Showmydetails.aspx" title="Show my details" />
       <siteMapNode url="Editmydetails.aspx" title="Edit my details" />
     </siteMapNode>
  </siteMapNode>
</siteMap>

其他和前一种方式一样。

总结:其实说了半天,要点就是应用Security Trimming功能,启用了这个功能后,就不用像文章中那么繁琐的实现这个功能了。