|
Hello !
I am building a MVC 5 app in which there will be 4 types of users . (Admin , HR Member , Managers , Employee) . I already created the views and the controllers for each type .
I want to give each manager access to certain departments , and the employee access to data according to his employeeID value .
After reading several articles on the Internet about this topic , I suppose I have to assign each user type a role and each department/employeeID a permission , but I have no clue on how to do that .
Can someone explain to me how to implement this ? I mention that the Identity Framework installed on the project is at version 1.0 .
|
|
|
|
|
You need to create Roles & Permissions. You need to create a table (like "Roles") that store the Roles
In your app there is 4 Roles
1- Admin
2- HR Member
3- Managers
4- Employee
And need to store all the permissions in a Table (like "Permission" table).
for each Role you need to map the permissions means to specify what are the permission available for Admin, HR Member, Managers & Employee. To do this you need to create a table (like RolesPermission) that contains the Id of Role and also the Ids of Permission that "One To Many" mapping. like
ID RoleId PermissionId
1 1 1
2 1 2
3 1 4
4 2 4
5 2 5
... ... ...
After that you just need to assign the Role to the users. And where the user can access resources or not You just need to get Permissions of that user and check the permission that available to access the resources. If available then give access otherwise don't give access.
|
|
|
|
|
Ok , in other words I should have three classes :
Role
Permission
RolePermission(in which I should include two objects , one of type Role , and one of type Permission)
And I should link the RolePermission to the ApplicationUser , then apply the migration .
Is that correct ?
|
|
|
|
|
Yes
|
|
|
|
|
Ok , I got stuck again .
So I created the classes :
Role :
public class Role
{
public Role() { }
public Role(string name, int id):this()
{
this.RoleId = id;
this.Name = name;
}
[Key]
[Required]
public virtual int RoleId { get; set; }
public virtual string Name { get; set; }
}
Permission :
public Permission()
{ }
public Permission(string name,int id):this()
{
this.Name=name;
this.Id = id;
}
[Key]
[Required]
public virtual int Id { get; set; }
public virtual string Name { get; set; }
}
RolePermission :
public class RolePermission
{
public Role Role { get; set; }
public Permission Group { get; set; }
[Required]
public int RoleGroupId { get; set; }
public RolePermission() { }
}
I updated the ApplicationUser class
public class ApplicationUser : IdentityUser
{
public ApplicationUser()
: base()
{
this.Permission=new HashSet<RolePermission>();
}
[Required]
public string Name { get; set; }
public virtual ICollection<RolePermission> Permission { get; set; }
}
Is this correct up to this point ?
I suppose I should modify the ApplicationDbContext , which , up to this point , looks like this :
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
}
What changes should I do ?
|
|
|
|
|
Yes you are right. You should use this one
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
}
|
|
|
|
|
It worked . Thank you very much !
|
|
|
|
|
hi . i have two website ballychohan.com and baljinderchohan.com. both are in php. i want to integrate both in single domain. what to do
|
|
|
|
|
|
gauravkumar02 wrote: both are in php
And what does that have to do with ASP.NET?
Also, you might want to get a native English speaker to proof-read your text. Your site is full of basic grammatical and punctuation errors, which gives an extremely poor first impression - particularly for a company which claims to be based in the UK!
And for that matter, why would you want to combine the website of "a leading IT company" with that of a supplier of "Indian Cuisine in the UK"?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
... and the "Testimonials" are from companies that don't exist.
|
|
|
|
|
Hm, perhaps that was an SEO attempt? But he failed to set up proper links to his web sites...
And it could be an interesting combination: buy a webhosting package, get a pappadum for free.
|
|
|
|
|
Hi,
I am trying to load an SWF flash file in an ASP.NET page. embed URL is pointing to the file in my D:\ drive.
Can you please tell me whats wrong in the below code? Movie not loaded message is coming.
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0"
width="980" height="634">
<param name="movie" value="video/D:\Articulate\story.swf" />
<param name="quality" value="high" />
<embed src="video/D:\Articulate\story.swf" width="”980" height="634" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer"
type="application/x-shockwave-flash" wmode="transparent" />
</object>
Thank You
Suresh Katari
|
|
|
|
|
You're doing it wrong. Remove the Video/ before the path.
You should not use absolute path. Use relative path. Save the swf file in same path where you have the html file.
Check this for simple example. HTML - Plug-ins[^]
|
|
|
|
|
Thank you raja. As you mentioned "video/" is wrong and absolute path is also wrong.
By my requirement is i have a set of SWF files which will be in a network shared folder and i have to access them in my asp.net page. So i must use absolute path in the src. Is this can be done? or i must copy all those SWF files to my web folder?
|
|
|
|
|
|
Understood. Thank you so much for your time.
|
|
|
|
|
Venturing into the Web API arena after years using WCF so!
If I have a service built on 4.51 serving up Json objects can that be consumed by a WPF client using 4.0
Is it reasonable to create a Web API service WITHOUT MVC, this will be consumed by various clients including MVC and WPF bit I want them in a separate projects.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I assume that the last statement meant to be a question...
It makes all the senses to separate common functionality from other layers. There is no technical problem to create pure WEB API projects (the only problem is that you will have to build it manually from scratch or by cleaning a project created by the wizard)...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
Almost all examples are for 4.5(1) and include MVC, as I know very little about MVC I struggle to separate the them. One article I was working through requires the project to be published to test it, painful.
What I am really looking for is an example of a plain Web API project consumed by a WPF client.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
There is a ways to create an WEB API only project (in VS 2013), but I never checked it... Choose Empty ASP.NET Web Application, int the 'Add folders and core references for:' section choose WEB API...
If 4.5 does not fit you, you can open project properties and change target framework...(no idea what wrong with 4.5, I do use 4.5.2)
These two links may help you on how to access such a WEB API from WPF:
http://www.asp.net/web-api/overview/web-api-clients/calling-a-web-api-from-a-net-client[^]
Calling ASP.NET WebAPI using HttpClient[^]
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
Hi all,
We recently upgraded our web application from Windows server 2003 to Windows server 2008. Everything works good except that the Gridview footer controls' id are generating different. This is causing some external javascript failure. The Gridview code is:
<asp:UpdatePanel ID="UPSposors" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="grvSponsors" Visible="true" AutoGenerateColumns="false" HeaderStyle-Font-Names="Verdana"
HeaderStyle-Font-Size="9pt" PageSize="5" ShowFooter="true" TabIndex="9" runat="server"
OnRowCancelingEdit="grvSponsors_RowCancelingEdit" OnRowEditing="grvSponsors_RowEditing"
OnRowUpdating="grvSponsors_RowUpdating">
<Columns>
<asp:TemplateField HeaderStyle-Width="100px" SortExpression="SponsorType" HeaderText="Contact Type">
<EditItemTemplate>
<asp:DropDownList ID="ddlEditSponsorType" runat="server" Width="99px" Font-Names="Verdana"
Font-Size="8pt">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblSponsor" runat="server" Text='<%# Bind("SponsorType") %>' Font-Names="Verdana"
Font-Size="8pt" /></a>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlAddSponsorType" runat="server" Width="99px" Font-Names="Verdana"
Font-Size="8pt" TabIndex="13">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvAddSponsor" runat="server" Display="Dynamic" ErrorMessage="Business Contact-Contact Type is required."
InitialValue="" Enabled="false" ControlToValidate="ddlAddSponsorType"><strong>!</strong></asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:CommandField FooterText="<U><a style='cursor:hand;font-family:Verdana;font-size:8pt;padding:2px;' TabIndex ='14' id='aAdd' onclick='TriggerAddSponsor();' >Save</a></U>"
ShowDeleteButton="true" ShowEditButton="true" HeaderStyle-Width="125px" CausesValidation="false"
ControlStyle-Font-Names="Verdana" ControlStyle-Font-Size="8pt" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
The generated HTML control in Windows Server 2003 is:
<td>
<select name="tcGeneral$tpGeneral$grvSponsors$ctl03$ddlAddSponsorType" id="tcGeneral_tpGeneral_grvSponsors_ctl03_ddlAddSponsorType" tabindex="13" style="font-family:Verdana;font-size:8pt;width:99px;">
<option value="">Select</option>
<option value="BUS">Business</option>
<option value="IT">IT</option>
<option value="SP">Sponsor</option>
</select>
<span id="tcGeneral_tpGeneral_grvSponsors_ctl03_rfvAddSponsor" style="color:Red;display:none;"><strong>!</strong></span>
</td>
The generated HTML control in Windows Server 2008 is:
<td>
<select name="tcGeneral$tpGeneral$grvSponsors$ctl03$ddlAddSponsorType" id="tcGeneral_tpGeneral_grvSponsors_ddlAddSponsorType" tabindex="13" style="font-family:Verdana;font-size:8pt;width:99px;">
<option value="">Select</option>
<option value="BUS">Business</option>
<option value="IT">IT</option>
<option value="SP">Sponsor</option>
</select>
<span id="tcGeneral_tpGeneral_grvSponsors_rfvAddSponsor" style="display:none;"><strong>!</strong></span>
</td>
As you can see the id generated for W2K3 server has "ctl03" in it but the W2K8 does not. This is causing our javascripts to fail. On my laptop running IIS7.5 the id has "ctl03" its just on the windows server 2008 that is missing it. Am I missing some kind of setting or deployment?
Thank you for any help in advance,
AJ
|
|
|
|
|
|
Thank you Richard. That solved the problem. I did set the framework to 4.0 however on my and other developer's localhost the client id was generating as it always did. Only when we deployed it to Windows 2008 server that we ran into this issue. Any idea why the client id is generating as "AutoID" on local machines but not on the W2K8 server?
Thank you again for your help.
AJ
|
|
|
|
|
That's odd. Are you sure your local copy was running under IIS, and not the Visual Studio web-server?
Also, have a look at the web.config files; it's possible that your local file was upgraded to .NET 4.0 and had the application-wide default set to AutoID , whereas the deployed file didn't have that setting.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|