Converting Declaractive PrincipalPermission To Programmatic?

Dec 21, 2010

I currently have two roles like this:

[PrincipalPermission(SecurityAction.Demand,
Role="DomainAdmin")]
[PrincipalPermission(SecurityAction.Demand,
Role="DomainAnotherRole")]

The problem is that this inherited code is specific to the domain, and I want to eventually get the roles from the web.config file, so I can work on a VM not in the domain. have seen an example like this:

PrincipalPermission permCheck = new PrincipalPermission(
null,
@"DomainAdmin");
permCheck.Demand();

Since this throws an exception if user is not in role, how do I change this example to allow either of the two roles? I could use multiple IPrincipal.IsInRole() and then throw my own exception, but seems like there is probably a way to use the .Demand method with multiple roles. Update 12/21: Sample Code based on Union link from Ladislav's answer below:

PrincipalPermission ppAdmin = new PrincipalPermission(null, @"DomainAdmin");
PrincipalPermission ppAnother = new PrincipalPermission(null, @"DomainAnotherRole");
(ppAdmin.Union(ppAnother)).Demand();

View 1 Replies


Similar Messages:

C# - How To Handle PrincipalPermission Security Exceptions

Feb 28, 2011

I have a simple method that is secured

[PrincipalPermission(SecurityAction.Demand, Role = "Administrator")]
protected void lnkClearCache_Click(object sender, EventArgs e)
{
}

If this is clicked without the role, it generates a System.Security.SecurityException: Request for principal permission failed. as expected.

I use ELMAH to handle logging for my errors, and I have a custom ELMAH event in my global.asax to transfer to the error pages in ways that preserve status codes which works correctly.

[Code]....

This works all well and fine and redirects to my error page which works properly, however instead of displaying the content as expected. I immediately get a second request for the error page but this time using the value of customErrorsSection.DefaultRedirect that does not come from my code in any way that I can see.

As far as I can tell it's almost as if when .NET raises an exception for PrincipalPermission and then lets the entire request complete, then after the request is complete it throws away the application response and instead responds with the default custom error.

When I'm debugging I do break on 2 separate exceptions for PrincipalPermission, whether this is a just a rethrow by .NET I'm not sure but my .NET code never sees the 2nd throw, nor does ELMAH. I always end up with a single response, single error logged, but that the url that finally renders to the browser is the default url and not 403 url that I specifically server.transferred to. If I browse to a /location that is secure I properly get the 403 error page.

View 1 Replies

C# - PrincipalPermission Versus Web.config For Page Access Controls

Jul 13, 2010

I currently have my access permissions in web.config:

[code]....

This is a very weird one... I just added ASP.NET4 routing, which changes the URLs. So, all of a sudden my web.config permissions are no longer valid! Similar to point #2 above.

I was thinking it would be better to just use PrincipalPermission as security attributes for the classes/c# files involved in each aspx. My question:

More importantly... My PrincipalPermission attribute generates an exception (good) but does not redirect users back to the logon page (bad).

View 2 Replies

MVC.NET Tag For Checking Roles (equivalent Of Declarative Attribute PrincipalPermission)?

Apr 5, 2010

I use declarative roles in my MVC.NET controllers and I have a custom membership & roles provider.This works fine:

[Authorize(Roles = "ADMIN")]

Also, I have a base MVC.NET CustomController class that all controllers derive from, and it has a "currentUser" property that is auto-fetched from the session on demand, so all controller code just refers to "currentUser" and doesn't worry about sessions, httpcontext, etc. I've implemented the membership provider properly, as it works with other parts of the framework that just deals with providers, but until now I had not tried to access the "User" principal from a view.What is the simplest syntax for check roles in a view page? I know I can use a helper to generate a partial view but I don't want that here, I want to explicitly wrap some sections of a page in some role checks.Something like this:

<% if(currentUser.IsInRole("ADMIN") { %>
...
<% } %>

View 1 Replies

C# - Programmatic Logon To Crystal Reports Server?

Jan 9, 2010

I have a Web Forms app that uses forms authentication. I have a Crystal Reports Server 2008 V1 server with InfoView .NET installed and working. I have some Enterprise accounts setup. EDIT: I should mention that my Web Forms app is on a different server from Crystal Reports Server.

I need to know how to log on to InfoView .NET programmatically on my custom ASP .NET page (C#) and then transfer the user to InfoView without them having to type in the logon information.

Something like this would be nice (C#):

string username = "blah";
string password = "asdf";
// create logon token for crystal reports server
// .. // this is the code I need
Response.Redirect(url);

I did find this question, which gets me partway there, but it doesn't tell me how to pass the token to InfoView .NET. Some older docs also mention needing a cookie. I've also found other sites that show how to pass it to Java InfoView, but I need the .NET version.

View 1 Replies

Programmatic Referencing Of Literals And Object Properties?

Jul 15, 2010

I have advice that this might work for programmatically filling a set of literals from a set of object properties:-

[code]....

However, the line: ctl.Text = pageData.help(i).trim() fails because it's not understood that pageData.help(i) should translate to pageData.help1, pageData.help2, etc.

View 1 Replies

How To Add An Expires Or A Cache-Control Header Programmatic

Aug 2, 2010

i host my web site into a shared hosting and i need to set expiration header using iis but i didn't find my hosting allow this feature so , is there any way to set it into my web configuration or into my code ??

View 2 Replies

Programmatic Accessing A Control From Base To Derived?

Nov 15, 2010

In a recent post, I expressed a need to access the properties for the body using declarative syntax, see

Contentplaceholder for replacing attributes?

But, the syntax confuses the editor which is not acceptable.

My hypothesis for a workable solution is to make the change in code. To derive a class from System.Web.UI.Page with extended functionality. However, I want for the designer to be able to still use declarative syntax to set the body tag.

I do not want to have to change any code in my aspx web pages except that they derive from base I want to be able to set these properties using declarative syntax, merely by adding a tag in the derived page I'm not immediately sure how to go about doing this because it doesn't exactly fit the OOP paradigm and I'm not sure where the changes need to be made.

I can use a findcontrol in the base to see if the placeholder has been added. But, not sure exactly at what point in the page processing lifecycle that I can use this findcontrol. I need to set the body before it renders but also be able to grab something from the declarative code.

View 2 Replies

GridView SqlDatasource Programmatic Databinding Sorting?

Jan 27, 2010

I am databinding a SqlDatasource to a GridView in 2 different ways.

1) Declaring the SqlDatasource in the .aspx page and setting the DatasourceID property on the GridView to its id

2) Creating the SqlDatasource in the code behind and binding to the datasource property

When I use the declarative method (1), sorting works fine without any extra work on my part, but If I create the SqlDatasource in the code behind and try to sort, I get an exception saying 'The GridView 'myGridView' fired event Sorting which wasn't handled'.

I assume that there is some sort of extra plumbing that occurs when using the first method. Does anyone know what the datasourceid method does that the programmatic one doesn't? I would like to duplicate the logic in the code behind if possible.

View 1 Replies

Web Forms :: Do A Programmatic HTTP Post To Another Site

Nov 29, 2010

I need to POST to an external HTTPS url from my application. I am looking for a 'robust' way to do this, in code if possible.

I would just like to use error handling etc, rather than just blinding doing the normal post and hoping it works.

Can you do HTTPS POST from some page event using server side code?

View 3 Replies

DataBind Formview To Function With Programmatic Type

Aug 4, 2011

I'm trying to databind a formview to the following two functions. IODS doesnt like the "of configtype as new"

Public Shared Function GetConfig(Of configtype As New)() As configtype
End Function
Public Shared Function SetConfig(ByVal configItem As Object) As Boolean
End Function

View 2 Replies

Security :: Programmatic Impersonation Access Denied To UNC Path

Jun 4, 2010

Programmatic impersonation access denied to UNC path

[WebMethod]

View 1 Replies

Web Forms :: Programmatic Server Side Conversion To PDF From HTML - Word And Excel

Dec 17, 2010

Sorry, not sure if this is the right place for this. I have a requirement to convert Word, Excel and HTML docs to PDF format programmatically, but most information online seems to be talking about client side. What is the best approach for this. I think there would be about 100 conversions a day in production. It's not high volume.

View 2 Replies

Web Forms :: ASP:TABLE And Get The Postback Data From A Programmatic Generated Radio Buttons In TableCell Object

Sep 13, 2010

I am having a bit of trouble trying to get teh postback data from a programmatic generated radio buttons in TableCell object. I have the following ASP user control:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="wcntrlCallFlow.ascx.cs" Inherits="CallEvaluation.wcntrlCallFlow" %>
<style type="text/css">
.TableDev
{
width: 100%;
border-style: solid;
border-width: 1px;
border-color: Black;
}
.HeaderRowStyle
{
width: 100%;
border-style: solid;
border-width: 1px;
border-color: Black;
background-color:#33CCCC;
}
.DetailRowStyle
{
width: 100%;
border-style: solid;
border-width: 1px;
border-color: Black;
background-color:White;
}
</style>
<asp:Table ID="tblControl" runat="server"/>

I generate the TableRow and TableCell base off XML data file. When the submit occurs I can not access the data values from the radio buttons that are generated. I try to get the data in the following manner:

if(Request[objRadioName].Checked)
{
this.value = 5;
this.ReCalc();
}

I notice that in the Request object the table row name is passed back like: "wcntrlCallData1$wcntrlCallFlow1$CallFlow".

View 4 Replies

Converting From PSD To PNG?

Nov 29, 2010

is there any software I can use that allows me to programmatacilly convert a PSD into a PNG in my asp.NET web application? Where transparenct and quality are preserved.

View 2 Replies

Converting String To Int?

Mar 10, 2010

i'm having a hard time figuring the way on converting my string into an integer number.In my form I have a textbox control from which I get the selected date as string, using the substring method I divide it to month, day and year.The problem is that I cannot, for example, convert the following "12" into the actual integer number twelve. I tried using Int32.Parse or Convert.ToInt32 but still couldn't solve it.Here's my code behind for better comprehension (this doesn't do the trick):

[Code]....

View 5 Replies

MVC :: Converting A Webforms App To Mvc?

Aug 7, 2010

I am converting a webforms app to mvc. I implemented localization in webforms this way: The user selects the language, which BTW can be an rtl language, and the selection goes into the user profile in order for it to persist the next time the user visits the site. I used anonymous profiles. also, I used resource files.The db tables have multiple rows for each language (with a language index field). I also used different style sheets for ltr and rtl languages since I don't use tables on my site (Is there another way instead of using separate style sheets?) What are the best practices for using localization in asp.net mvc ? can I and should I use resource files ? and profiles ? should I map the aspnet tables to linq-to-sql ?

View 1 Replies

C# Converting Int To Int64?

Oct 29, 2010

we are in the process of upgrading our crappy cms system and the new assemblies have changed from int to int64. I'm running into a problem when trying to build now. here is one excerpt of code that is causing a problem.

IDictionary<int, string> aliases
= new UrlAliasApi().GetUrlAliasesByType(
Company.DataLayer.Enumeration.UrlAliasType.Recipe);
foreach (ContentBase recipe in mergedResultset)
{
// if alias exists, overwrite quicklink!
string alias;
if (aliases.TryGetValue(recipe.Id, out alias))
{
recipe.QuickLink = alias;
}
}

The error is

Error 323 The best overloaded method match for 'System.Collections.Generic.IDictionary.TryGetValue(int, out string)' has some invalid arguments Its referring to recipe.Id which is an Int64 value.

View 5 Replies

Converting Vb.net Into A Web Application?

Sep 23, 2010

I have written a desktop application in vb.net. Now I need to convert it into a web application in asp.net. Can you please suggest how I might proceed?

View 1 Replies

Converting C# Razor To VB?

Feb 28, 2011

I'm following the ASP.NET MVC Tutorial and having started in VB.NET I'm having trouble converting the following razor code:

I have got

<ul>
@For Each g As MvcApplication1.Genre In Model
<li> @g.Name </li>
Next
</ul>

but getting

Attribute Sepcifier is not a complete statement on both the <li> tags. I understand I need to use line continuation but can't figure out where.

View 3 Replies

Converting VB To C# DateTime?

Jan 23, 2010

I am trying to convert some code I wrote from VB to C# and it regards Date, Times, and TimeSpans

[Code]....

the First Issue I have is with formats, I have a countdown that displays days left to enter the drawing, I just want a + int displayed no decimals, right now it shows 343.91736271538735 days left to enter drawing.

On The Page it displays Something Like this:

Drawing Date: Sunday, January 1, 2010

Days Left to Enter: 343 Days left to Enter

Right Now it Displays

Days Left To Enter :343.062117332176 Days Left to Enter

View 2 Replies

Converting To A Repeater

Jan 28, 2013

im trying to convert this into a repeater but finding it a little difficult trying to figure out how to seperate it and make it work.
Basically the original code is HTML, and I want to use that but since my menu system is coming from a DB, I want to be able to bind that menu system and have it automatically just bind the menus with the x level deep nav bars etc... which this HTML code does:

[URL]

(download the zip file)

Sure, 1 repeater on the page but because this is generic, I know I dynamically have to create and add a repeater and bind the submenu items (and their children if any) to this repeater...and adding this repeater to the current item.

View 1 Replies

Converting Textbox.text To Int?

Jul 27, 2010

I have a text box; txtPriceQuoted, and want to submit it's value to my SQL Server Database, I get an error about the conversion:

"Conversion failed when converting the varchar value '12.5' to data type int."The error only occurs when there is a decimal point in the number, how should i convert it so that I can input the value into my database....?

View 13 Replies

Converting VB To C# - What Is Proper Syntax

Jul 6, 2010

I am trying to conver this to C# but Item is not a method in C#

Repno is a string variable of 3 characters

First if rep is not null

then

confirm that Repno the field salespnno from the query.

[code]....

View 2 Replies

Web Forms :: Converting Aspx To PDF?

Oct 3, 2010

[code]....

the above code only converts controls in dvtext (div) like label name and textboxname to pdf. after entering values into textboxes. it is not convert them to pdf. it only converts control names.

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved