views:

38

answers:

4

I have given the particular permission for the particular user. Only that menu will be enabled which permission is set for that user.

I have two problems....

1) Menu item should be invisible rather than disable

2) If any User copy the page name which it has no access and can open it..

Suggest any....(urgent)

+1  A: 

you can add this in the page load

if (!HttpContext.Current.User.IsInRole("YourRole"))
        {
            Response.Redirect("~/AccessDenied.aspx");
        }
Muhammad Akhtar
A: 

You should look into the <location> element in <system.web> section of web.config. There you can set access rules as simple as

<authorization>
    <allow roles="Admin" /> <!--allows access to admins-->
    <deny users="*" /> <!-- denies access to any other users -->
</authorization>

More info here

Tomas Lycken
This will deny users to the pages but it will not feed into permissions on a menu control. From the original question it looks like he's trying to hide one branch of the menu depending on the user's logged in permissions.
Brian Scott
@Brian, Actually, if he uses the `<asp:Menu>` control and defines his menu in a `web.sitemap` file, these rules *will* apply.
Tomas Lycken
@diptikantsahu, In that case, you probably just want an if-clause in your Page_Load method (much like Muhammad Akhtar suggested) that checks if the user has permission, and if not redirects to the home page or something. However, I would strongly recommend that you implement your own MembershipProvider, to make use of all the goodies that .NET has built-in and ready to go.
Tomas Lycken
A: 

you can manage the menu security by using ASP.NET Site-Map Security Trimming but if you want to prevent the uses from accessing the page through the url you can use put it inro your web.config file like:

<location path="securedAdministrationPage.aspx">
  <system.web>
    <authorization>
      <deny users="*" />
      <allow users="*" roles="Admins"/>
    </authorization>
  </system.web>
</location>

this link will help you http://wiki.asp.net/page.aspx/653/aspnet-webconfig--location-and-authroization-tags/

Pr0fess0rX
A: 

I would suggest putting your navigation into an user control and then use a switch statement or such, as well as the location section in the webconfig.

In the switch statement you can then use the 'Visible' attributes to hide the nav links (make sure they have a runat="server") from the users who do not have permission to view certain pages, dependant on their role (if using asp.net membership)

JamesStuddart