默认状态下,文章可以被搜索引擎找到网页地址,且能打开并访问之。某些栏目如果不希望被访问到,需要修改页面代码。
步骤如下:
在WebUser类中添加如下方法:
public static bool HasReadPermissions(int siteID, int moduleID, int pageID)
{
if (HttpContext.Current == null || HttpContext.Current.User == null) return false;
if (IsAdmin || IsContentAdmin) return true;
Module module = new Module(moduleID, pageID);
PageSettings pageSettings = new PageSettings(siteID, module.PageID);
if (IsInRoles(pageSettings.AuthorizedRoles) || IsInRoles(module.AuthorizedEditRoles))
{
return true;
}
if (module.EditUserID > 0)
{
SiteSettings siteSettings = (SiteSettings)HttpContext.Current.Items["SiteSettings"];
SiteUser siteUser = new SiteUser(siteSettings, HttpContext.Current.User.Identity.Name);
if (module.EditUserID == siteUser.UserID)
{
return true;
}
}
return false;
}
{
if (HttpContext.Current == null || HttpContext.Current.User == null) return false;
if (IsAdmin || IsContentAdmin) return true;
Module module = new Module(moduleID, pageID);
PageSettings pageSettings = new PageSettings(siteID, module.PageID);
if (IsInRoles(pageSettings.AuthorizedRoles) || IsInRoles(module.AuthorizedEditRoles))
{
return true;
}
if (module.EditUserID > 0)
{
SiteSettings siteSettings = (SiteSettings)HttpContext.Current.Items["SiteSettings"];
SiteUser siteUser = new SiteUser(siteSettings, HttpContext.Current.User.Identity.Name);
if (module.EditUserID == siteUser.UserID)
{
return true;
}
}
return false;
}
对与要控制的页面,修改Page_Load 方法,如下:
private void Page_Load(object sender, EventArgs e)
{
SecurityHelper.DisableBrowserCache();
LoadParams();
if (!WebUser.HasReadPermissions (siteSettings.SiteID, ModuleID, CurrentPage.PageID))
{
SiteUtils.RedirectToAccessDeniedPage();
}
if (parametersAreInvalid)
{
this.pnlBlog.Visible = false;
return;
}
GetModuleSettings();
SetupCss();
PopulateLabels();
if (!IsPostBack && ModuleID > 0 && ItemID > 0)
{
if (Context.User.Identity.IsAuthenticated)
{
if (WebUser.HasEditPermissions(siteSettings.SiteID, ModuleID, CurrentPage.PageID))
{
IsEditable = true;
}
}
PopulateControls();
}
}
{
SecurityHelper.DisableBrowserCache();
LoadParams();
if (!WebUser.HasReadPermissions (siteSettings.SiteID, ModuleID, CurrentPage.PageID))
{
SiteUtils.RedirectToAccessDeniedPage();
}
if (parametersAreInvalid)
{
this.pnlBlog.Visible = false;
return;
}
GetModuleSettings();
SetupCss();
PopulateLabels();
if (!IsPostBack && ModuleID > 0 && ItemID > 0)
{
if (Context.User.Identity.IsAuthenticated)
{
if (WebUser.HasEditPermissions(siteSettings.SiteID, ModuleID, CurrentPage.PageID))
{
IsEditable = true;
}
}
PopulateControls();
}
}