Showing posts with label role. Show all posts
Showing posts with label role. Show all posts

Monday, March 12, 2012

Programmatically Specify SqlDataSource Parameters

I have a GridView bound to a SqlDataSource. On page load I would like to programmatically specify a SelectParameter value based on the role of the user. This SelectParameter will be used in my WHERE clause. The closest post I can find ishttp://forums.asp.net/thread/1233258.aspx but no answer was posted.

What code would I use to modify a SelectParameters value? Is it possible to reference a parameter by name (SqlDataSource1.SelectParameters["usertype"]) or does it have to be by index? (SqlDataSource1.SelectParameters[0])

Alternatively, perhaps I'm going about this in the wrong way, is there a better way to have dynamic GridView content based on the role of the user?

Thank you very much for your help.

Yes, you can set the value of a select parameters by name, for example
SqlDataSource1.SelectParameters["usertype"].DefaultValue ="role"
|||

Both parameter name and index are working here.

protected

void Page_Load(object sender,EventArgs e)

{

SqlDataSource1.SelectParameters[0].DefaultValue=

"yourvalue";

or

SqlDataSource1.SelectParameters["usertype"].DefaultValue="yourvalue";

}

|||

You can also set the value in the SqlDataSource_Selecting event via the e parameter:

Private Sub SqlDataSource1_Selecting(stuff)

e.command.paramter("param1").value=something

end sub

Friday, March 9, 2012

Programmatically doing new role assignments

Hello everyone -
A friend of mine is having some trouble using the browser based method
of assigning roles and I suggested that we do it programmatically just
in case errors were being suppressed by IE. So far I've seen a lot of
code that creates roles but none that assigns the role to a Windows
group. So for example, I've seen code that can build a role called FOO
with tasks A,B,C associated but how can I assign WINDOMAIN\Users to
that role?
Thanks much,
David SeruyangeJust in case anyone else runs into this, it is done with a policy
object - a short snippet of code like this will do the trick:
MyRS.ReportingService tmp = new MyRS.ReportingService();
// below the NetworkCredential class accepts 3 arguments:
// USERNAME, PASSWORD, DOMAIN
// this is to connect to ReportServer so use an admin account
tmp.Credentials = new NetworkCredential("myusername", "mypassword",
"MYDOMAIN");
try{
Role[] roles = tmp.ListRoles();
foreach(Role r in roles){
if(r.Name == "Browser"){
// modify 'r'
bool bInherit;
Policy[] polis = tmp.GetPolicies("/", out bInherit);
Policy[] pcopy = new Policy[polis.Length + 1];
Array.Copy(polis, pcopy, polis.Length);
Policy np = new Policy();
// MAKE THIS USERNAME CORRESPOND WITH A
// DOMAIN ACCOUNT
np.GroupUserName = @."DOMAIN\User";
np.Roles = new Role[]{r};
pcopy[pcopy.Length -1] = np;
// ASSIGN THIS to the FOLDER that contains
// your report off the ROOT "/"
tmp.SetPolicies("/REPORTFOLDER",pcopy);
Console.Write("Policy assignment has been made.");
}
}
}
catch(Exception ex){
Console.WriteLine(ex.ToString());
}|||david.seruyange@.gmail.com wrote:
> group. So for example, I've seen code that can build a role called
> FOO with tasks A,B,C associated but how can I assign WINDOMAIN\Users
> to that role?
David,
look at bryan's blog under http://blogs.msdn.com/bryanke/articles/91726.aspx
You will find a really good example-script
regards
Frank

Wednesday, March 7, 2012

Programmatically adding a user to the System User role

We have been working on an application that will be using a forms-authenticated report server (RS2005) as a reporting back-end. Using the reporting services web service I have been able to assign permissions to objects in reporting services no problem. The issue is that each user needs to be added to the System User role to be able to use the report builder properly. I can't seem to find a way to do this programmatically. Any idea?Nevermind, GetSystemPolicies() is what I was looking for.