随笔 - 547  文章 - 213 评论 - 417 阅读 - 107万

WeblogTemplatedWebControl类的源代码

概述:
这个类是Weblog的页面的模版类

类图如下:



1. CurrentWeblog属性
        private Weblog weblog = null;

        
/// <summary>
        
/// Returns the CurrentWeb and calls Authorize
        
/// </summary>
        public virtual Weblog CurrentWeblog
        {
            
get
            {
                
if(weblog == null)
                {
                    weblog 
= Weblogs.GetWeblog(CSContext.Current.ApplicationKey,true);

                    
if(!this.CurrentUser.IsBlogAdministrator)
                        Authorize(weblog);
                }

                
return weblog;
            }
        }


这个属性是公有的,作用是:Returns the CurrentWeb and calls Authorize。
具体步骤如下:
(1) 用到了Weblogs.GetWeblog方法和CSContext.Current.ApplicationKey属性,用来得到当前的Weblog对象,
(2) 如果当前用户不是管理员,就调用本类的Authorize方法,判断用户是否具有Permission.View权限。


 

2.Authorize(Weblog w)方法

        /// <summary>
        
/// By default, checks to see if a blog exists and if the user has read access
        
/// </summary>
        
/// <param name="w"></param>
        protected virtual void Authorize(Weblog w)
        {
            
if(w == null)
                PermissionBase.RedirectOrExcpetion(CSExceptionType.SectionNotFound,
string.Format("Weblog {0} could not be found",CSContext.Current.ApplicationKey));

            Permissions.AccessCheck(w,Permission.View,
this.CurrentUser);
        }

该方法是protected方法,只能被它的子类调用。作用是:By default, checks to see if a blog exists and if the user has read access.
具体步骤是:
(1) 判断传入的Weblog对象是否存在,如果不存在就抛出异常。
(2) 检查当前用户是否具有Permission.View权限


由此:可得该类的类图已经关联类图如下:

(还有一个枚举类型没有在图中表现出来,具体原因见如何让VISIO显示枚举类型时只显示名称?)

 

posted on   今夜太冷  阅读(222)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示