Expand ASP. NET membership permissions (4) page Permissions

Source: Internet
Author: User

 

Previously, we introduced how to display buttons in different user groups. Now, if this is a page for access to group B with new function permissions, how can I prompt when group A comes in?

1.Httpmodule. CS

  

Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Using system. Web;
Using system. Web. Security;

Namespace EC. Permissions
{
Public class httpmodule: ihttpmodule
{

# Region ihttpmodule members

Public void dispose ()
{

}

Public void Init (httpapplication context)
{
Context. acquirerequeststate + = new eventhandler (context_acquirerequeststate );
}

Void context_acquirerequeststate (Object sender, eventargs E)
{
If (httpcontext. Current. User! = NULL)
// Check whether the user logs on and whether the user has page Permissions
If (httpcontext. Current. User. Identity. isauthenticated)
{
// Check whether the current page is in the configuration file
If (! Dal. checkpage ())
{
// You can extend it here
Httpcontext. Current. response. Write ("You are not authorized to access this page ");
}

}
}

# Endregion
}
}

 

 

 

2. Open Web. config in webroot.

Add <Add name = "httpmodule" type = "EC. permissions. httpmodule"/>

  

  3. Create print. aspx in admin/test/print. aspx

Access promptYou are not authorized to access this page.

 

Add in admin/test/Web. config

<Item>
<Page> Print. aspx </Page>
<Function> Print </function>
<Val> 64 </Val>
</Item>

 

  Add SQL

Insert into aspnet_ex_permissionsforroles
(Roleid, modulepath, permissionvalue) Values
('Your roleid', '/Admin/test/print. aspx', 64)

  

Print. ASPX page code

  

<% @ Page Language = "C #" autoeventwireup = "true" codefile = "print. aspx. cs" inherits = "admin_test_print" %>
<% @ Register Assembly = "EC. Permissions" namespace = "EC. permissions. webcontrols" tagprefix = "PC3" %>

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> hubj.cnblogs.com </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
Print. aspx
<PC3: permissionsbutton id = "permissionsbutton1" runat = "server">
<PC3: buttonitem text = "print" type = "print"/>
<PC3: buttonitem text = "return" type = "list"/>
</PC3: permissionsbutton>
</Div>
</Form>
</Body>
</Html>

 

 

Preview

  

 

Careful friends will find out why the returned results are not displayed? Update the SQL statement to 66 (print + list)

 

For example, the interface for how to manage permissions in the background is not described. If you are interested, you can try to update insert Delete.Table: aspnet_ex_permissionsforroles

  From four o'clock P.M. till now, I have finished writing. Welcome to the discussion.

  End :)

 

 

Directory

Expand ASP. NET membership permissions (4) page Permissions
Permission Control for ASP. NET membership extension (3)
ASP. NET membership permission extension (2)
ASP. NET membership permission Extension function (1)

 

 

Related Article

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.