3 Replies - 1198 Views - Last Post: 15 August 2012 - 06:10 AM Rate Topic: -----

#1 mil1234  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 109
  • Joined: 01-February 09

Asp MVC login authentication

Posted 15 August 2012 - 05:39 AM

Hi to all,

what i am trying to do is that in site.master i do some code which helps me display the navigation menu only if user is logged in. I achieved this by doing
 <% if (Context.User.Identity.IsAuthenticated){ show menu........

i know want to add a little bit more to my authentication as besides checking if user is Authenticated(logged in), i check also with my table in sql server if user isAdmin(which is a field in my users table)...anyone have an idea on how i accomplish this?

i am using linq to sql and as i said i am trying to implement this into site.master.

Thanks rgd's....

Is This A Good Question/Topic? 0
  • +

Replies To: Asp MVC login authentication

#2 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1004
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: Asp MVC login authentication

Posted 15 August 2012 - 05:47 AM

Have you considered using Roles within your application?

If you do, you will be able do a check that is somewhat simple like so:
if (HttpContext.Current.User.IsInRole("Administrators")) {
   // Do whatever
}

Was This Post Helpful? 0
  • +
  • -

#3 mil1234  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 109
  • Joined: 01-February 09

Re: Asp MVC login authentication

Posted 15 August 2012 - 05:51 AM

Hi,

it a good idea, but can i relate this to my users tbl (is Admin) field?

Thanks ..
Was This Post Helpful? 0
  • +
  • -

#4 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1004
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: Asp MVC login authentication

Posted 15 August 2012 - 06:10 AM

Well no, because you'd be setting up a more structured way of authenticating users for your application (Roles!).

If you need to check if they're an admin, you can simply add a helper that takes (for example) a username and performs a query to ascertain whether they have the isAdmin flag checked or not.

You could wrap this all in a helper class for Authentication, that performs the check for whether they're logged in or not and loads all relevant information as appropriate. From then on, you can simply call a method such as CurrentUser.IsAdministrator() to get a bool back as to whether they are both logged in and an administrator of the site.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1