CREATE TABLE [dbo].[PageElement](
[PageElementID] [int] IDENTITY(1,1) NOT NULL,
[Descrip] [varchar](50) NOT NULL,
[UrlPattern] [varchar](300) NOT NULL,
[Selector] [varchar](300) NOT NULL,
CONSTRAINT [PK_PageElement] PRIMARY KEY CLUSTERED
(
[PageElementID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
/*-----------------------------------------------------------------------------------------------*/
CREATE TABLE [dbo].[PageElementRole](
[PageElementRoleID] [int] IDENTITY(1,1) NOT NULL,
[PageElementID] [int] NOT NULL,
[RoleID] [uniqueidentifier] NOT NULL,
CONSTRAINT [PK_PageElementRole] PRIMARY KEY CLUSTERED
(
[PageElementRoleID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[PageElementRole] WITH CHECK ADD CONSTRAINT [FK_PageElementRole_aspnet_Roles]
FOREIGN KEY([RoleID]) REFERENCES [dbo].[aspnet_Roles] ([RoleId])
GO
ALTER TABLE [dbo].[PageElementRole] CHECK CONSTRAINT [FK_PageElementRole_aspnet_Roles]
GO
ALTER TABLE [dbo].[PageElementRole] WITH CHECK ADD CONSTRAINT [FK_PageElementRole_PageElement]
FOREIGN KEY([PageElementID]) REFERENCES [dbo].[PageElement] ([PageElementID])
GO
ALTER TABLE [dbo].[PageElementRole] CHECK CONSTRAINT [FK_PageElementRole_PageElement]
GO
create procedure [dbo].[GetPageElementsForUser]
(
@url varchar(1000)
,@username nvarchar(256)
) as
/*------------------*/
/*
declare
@url varchar(1000) = 'http://localhost:26335/Claim/Maintain/2'
,@username nvarchar(256) = 'pjasinski'
*/
/*------------------*/
declare
@result varchar(max)
;
with a as (
select distinct
pe.Selector
from
dbo.PageElement pe
inner join dbo.PageElementRole per
on pe.PageElementID = per.PageElementID
inner join dbo.aspnet_UsersInRoles uir
on uir.RoleId = per.RoleID
inner join dbo.aspnet_Users u
on u.UserId = uir.UserId
and u.UserName = @username
where 1=1
and @url like pe.UrlPattern
)
select
@result = coalesce(@result + '|', '') + Selector
from
a
select
result = @result
public string GetPageElementsForUser(string url, string username)
{
ObjectResult<string> chunks = Database.GetPageElementsForUser(url, username);
StringBuilder sb = new StringBuilder();
foreach (string chunk in chunks)
sb.Append(chunk);
return sb.ToString();
}
public static string GetPageElementsHtml()
{
StringBuilder sb = new StringBuilder();
sb.Append("<input type='hidden' id='uxPageElementsToShow' value='");
string username = HttpContext.Current.User.Identity.Name;
string url = HttpContext.Current.Request.Url.ToString();
DataProvider dp = new DataProvider(Common.RequestContext);
string e = dp.GetPageElementsForUser(url, username);
sb.Append(e.Replace("'", "''"));
sb.Append("'/>");
return sb.ToString();
}
<%if (Request.IsAuthenticated)
{
Response.Write(MySite.Web.Common.Security.GetPageElementsHtml());
%>
/*===============================================================================================*/
function isVisible(selector) {
return $(selector).is(':visible');
}
/*===============================================================================================*/
function enable(selector, enabled) {
if (!enabled) {
$(selector).attr('disabled', 'disabled');
}
else {
$(selector).removeAttr('disabled');
}
}
/*===============================================================================================*/
function show(selector, visible) {
if (visible)
$(selector).show();
else
$(selector).hide();
}
/*===============================================================================================*/
function enforceSecurity() {
// "override" this function in your page-specific javascript
// DO NOT call the enforceSecurity() function from your DOCUMENT.READY function!!!
//alert("This is the common [enforceSecurity]");
}
/*===============================================================================================*/
function enforceSecurityCommon() {
var itemsConcat = $('#uxPageElementsToShow').val();
if (itemsConcat != undefined) {
var items = itemsConcat.split('|');
for (i = 0; i < items.length; i++) {
show(items[i], true);
}
}
enforceSecurity();
}
/*===============================================================================================*/