Mojoportal Study Notes page Access Control

Source: Internet
Author: User
By default, an article can be found by the search engine and accessed. If you do not want to access some topics, You need to modify the Page code.

The procedure is as follows:
Add the following method to the webuser class:

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 );
Pagesetaskpagesetask= new pagesetask( siteid, module. pageid );
If (isinroles (pagesettings. authorizedroles) | isinroles (module. authorizededitroles ))
{
Return true;
}

If (module. edituserid> 0)
{
Sitesettings = (sitesettings) httpcontext. Current. items ["sitesettings"];
Siteuser = new siteuser (sitesettings, httpcontext. Current. User. Identity. Name );
If (module. edituserid = siteuser. userid)
{
Return true;
}
}

Return false;
}

Modify the page_load method for the page to be controlled as follows:

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 ();
}


}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.