Ask a Question related to ASP.NET Security, Design and Development.
-
localhost #1
Attribute Expression Must be a Constant - Problem
I decorated my assembly with the stuff below, but the compiler
complains "An attribute argument must be a constant expression, typeof
expression or array creation expression".
I want my assembly to obey CAS and only read and write to its own
application directory as well as %temp%. Any suggestions?
Thanks.
[assembly:
FileIOPermissionAttribute( SecurityAction.RequestMinimum,
Read=System.IO.Directory.GetCurrentDirectory() ) ,
FileIOPermissionAttribute( SecurityAction.RequestMinimum,
PathDiscovery=System.IO.Directory.GetCurrentDirect ory() ) ,
FileIOPermissionAttribute( SecurityAction.RequestMinimum,
Write=System.IO.Directory.GetCurrentDirectory() ) ,
FileIOPermissionAttribute( SecurityAction.RequestMinimum,
Read=System.Environment.GetEnvironmentVariable("TE MP")) ,
FileIOPermissionAttribute( SecurityAction.RequestMinimum,
PathDiscovery=System.Environment.GetEnvironmentVar iable("TEMP") ) ,
FileIOPermissionAttribute( SecurityAction.RequestMinimum,
Write=System.Environment.GetEnvironmentVariable("T EMP") )
]
localhost Guest
-
regular expression problem ? and * characters
Im writing a perl script now and this is part of the sricpt chomp = ($pattern = ARGV); for each(@thisarray) { if($_ =~ m/$pattern/i) {... -
Regular Expression Problem
I am trying to parse a relatively simple SQL query with a regular expression. All is going well except for one issue I don't seem to be able to... -
Problem with regular expression
I'm trying to use a regular expression to remove from the output of a call to ToString with an XML object, the text between "<?" and "?>" txtvar... -
php regular expression problem
Hi, I've got just a small problem, it's probably not very complex but I'm not very experienced with regular expression stuff. I just need to... -
sed expression problem ?
I am starting to use sed but am having a problem with one expression in ... cat /mnt/archive/fluxbox/keys | sed 's/:ExecCommand//g ;s/^Mod4 \(.\)... -
Yan-Hong Huang[MSFT] #2
RE: Attribute Expression Must be a Constant - Problem
Hello,
Thanks for posting in the group.
Based on the description, now you are adding attributes like
FileIOPermissionAttribute( SecurityAction.RequestMinimum,
Read=System.IO.Directory.GetCurrentDirectory() ) into assemblyinfo.cs
file. When you build the project, the compiler gives error message "An
attribute argument must be a constant expression, typeof expression or
array creation expression". Please feel free to post here if I have
misunderstood the problem.
I am afraid it is impossible to use a runtime expression in Attribute
arguments.
The instance of an attribute class is constructed by the compiler when the
compile detects an attribute applied to a target, and at this time the
assembly hasn't been completed yet. And then the compiler initializes any
public fields and properties have been specified. After that, the instance
of the attribute is serialized to the target's metadata table entry.
Please Note: all these are done by the compiler and there is not a way to
get any runtime variable. Even if you use typeof keyword, you can only get
those Types can be retrieved at compile time. To obtain the run-time type
of an expression, you can use the .NET Framework method GetType.
In order to achieve what you want, we need to do it programmatically, not
declaratively. Please refer to the following article on how to do it:
"Security in .NET: Enforce Code Access Rights with the Common Language
Runtime "
[url]http://msdn.microsoft.com/msdnmag/issues/01/02/CAS/default.aspx[/url]
Hope that helps.
Best regards,
Yanhong Huang
Microsoft Community Support
Get Secure! ¨C [url]www.microsoft.com/security[/url]
This posting is provided "AS IS" with no warranties, and confers no rights.
Yan-Hong Huang[MSFT] Guest



Reply With Quote

