Avoiding SecurityException: System.Security.Permissions.SecurityPermission
Avoiding SecurityException: System.Security.Permissions.SecurityPermission
am 12.01.2008 17:58:29 von Nathan Sokalski
I have a function that I wrote that add transparency to a
System.Drawing.Image. When using this function on my webhost, I receive the
error
SecurityException: System.Security.Permissions.SecurityPermission
I am still able to generate graphics, but if I use this function I receive
this error. The function does not attempt to access any other files or
resources, and it works when testing it locally. My webhost is
myhosting.com, and the code for my function (which can also be seen on my
website) is:
Imports System.Drawing
Imports System.Drawing.Imaging
Namespace NathanSokalski
Public Class Transparency
Public Shared Function MakeTransparent(ByVal oldbmp As Bitmap, ByVal
transparentcolor As Color) As Bitmap
Dim bmp As New Bitmap(oldbmp.Width, oldbmp.Height,
PixelFormat.Format8bppIndexed)
Dim palette As ColorPalette = bmp.Palette
Dim nextindex As Byte = 0
Dim bmpdata As BitmapData = bmp.LockBits(New Rectangle(0, 0,
oldbmp.Width, oldbmp.Height), ImageLockMode.WriteOnly,
PixelFormat.Format8bppIndexed)
Dim index As Integer
For i As UShort = 0 To 255
palette.Entries(i) = Color.Empty
Next
For y As Integer = 0 To oldbmp.Height - 1
For x As Integer = 0 To oldbmp.Width - 1
'Get the palette index of the current pixel
index = Transparency.InPalette(palette, nextindex, oldbmp.GetPixel(x,
y))
'If the color is not in the palette, add it at the next unused index
If index = -1 Then
palette.Entries(nextindex) = oldbmp.GetPixel(x, y)
index = nextindex
nextindex += CByte(1)
End If
'Set the pixel to the proper index
System.Runtime.InteropServices.Marshal.WriteByte(bmpdata.Sca n0, y *
bmpdata.Stride + x, CByte(index))
Next
Next
bmp.UnlockBits(bmpdata)
'If the specified transparent color is included in the palette, change
that color to transparent
If transparentcolor <> Color.Empty AndAlso
Transparency.InPalette(palette, nextindex - CByte(1), transparentcolor)
<> -1 Then palette.Entries(Transparency.InPalette(palette, nextindex -
CByte(1), transparentcolor)) = Color.FromArgb(0, 0, 0, 0)
bmp.Palette = palette
Return bmp
End Function
'Returns number of colors in bitmap
Public Shared Function ColorCount(ByVal bmp As Bitmap) As Integer
Dim palette As New Collections.ObjectModel.Collection(Of Integer)
Dim currcolor As Integer
For y As Integer = 0 To bmp.Height - 1
For x As Integer = 0 To bmp.Width - 1
currcolor = bmp.GetPixel(x, y).ToArgb()
If Not palette.Contains(currcolor) Then palette.Add(currcolor)
Next
Next
Return palette.Count
End Function
'Returns index of color in palette or -1
Private Shared Function InPalette(ByVal palette As ColorPalette, ByVal
maxindex As Byte, ByVal colortofind As Color) As Integer
For i As Byte = 0 To maxindex
If palette.Entries(i).ToArgb() = colortofind.ToArgb() Then Return
CInt(i)
Next
Return -1
End Function
End Class
End Namespace
Can anyone tell me a way to avoid this (or if there isn't one, a webhost
that doesn't prevent me from doing it)? myhosting.com's security policy for
ASP.NET 2.0 can be seen at:
https://support.myhosting.com/CustomerCare/KnowledgeBase/Art icle.asp?url=Documents/ASP/Where%2520can%2520I%2520find%2520 more%2520details%2520about%2520your%2520dot-NET%2520Security %2520Policy.htm
Thanks.
--
Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/
Re: Avoiding SecurityException: System.Security.Permissions.SecurityPermission
am 14.01.2008 11:52:23 von Leon Mayne
"Nathan Sokalski" wrote in message
news:%23MckbxTVIHA.1184@TK2MSFTNGP04.phx.gbl...
>I have a function that I wrote that add transparency to a
>System.Drawing.Image. When using this function on my webhost, I receive the
>error
>
> SecurityException: System.Security.Permissions.SecurityPermission
Which line of code is causing the exception? Is it because the bitmap
operations are trying to write to a temporary path and your web host is
disallowing write access to the temp folder?
Re: Avoiding SecurityException: System.Security.Permissions.SecurityPermission
am 15.01.2008 03:08:44 von Nathan Sokalski
I beleive the line of code that is causing the exception is the following:
System.Runtime.InteropServices.Marshal.WriteByte(bmpdata.Sca n0, y *
bmpdata.Stride + x, CByte(index))
Because the class does not read from or write to any files, I cannot imagine
what else it could be, since everything else is pretty much just using
properties of the BitMap.
--
Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/
"Leon Mayne" wrote in message
news:AB04703A-DE23-4941-9CF3-2E86899170A9@microsoft.com...
> "Nathan Sokalski" wrote in message
> news:%23MckbxTVIHA.1184@TK2MSFTNGP04.phx.gbl...
>>I have a function that I wrote that add transparency to a
>>System.Drawing.Image. When using this function on my webhost, I receive
>>the error
>>
>> SecurityException: System.Security.Permissions.SecurityPermission
>
> Which line of code is causing the exception? Is it because the bitmap
> operations are trying to write to a temporary path and your web host is
> disallowing write access to the temp folder?
Re: Avoiding SecurityException: System.Security.Permissions.SecurityPermission
am 15.01.2008 08:23:00 von Bob
You could be right. There is no guarantee that there are 256 entries in a
palette and you may be falling off the end...
You should certainly look at the declared number of palette entries before
you arbitrarily decide to look at a colour entry range of 0-255.
--
--
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting
http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
"Nathan Sokalski" wrote in message
news:eCnAOuxVIHA.5160@TK2MSFTNGP05.phx.gbl...
>I beleive the line of code that is causing the exception is the following:
>
> System.Runtime.InteropServices.Marshal.WriteByte(bmpdata.Sca n0, y *
> bmpdata.Stride + x, CByte(index))
>
> Because the class does not read from or write to any files, I cannot
> imagine what else it could be, since everything else is pretty much just
> using properties of the BitMap.
> --
> Nathan Sokalski
> njsokalski@hotmail.com
> http://www.nathansokalski.com/
>
> "Leon Mayne" wrote in message
> news:AB04703A-DE23-4941-9CF3-2E86899170A9@microsoft.com...
>> "Nathan Sokalski" wrote in message
>> news:%23MckbxTVIHA.1184@TK2MSFTNGP04.phx.gbl...
>>>I have a function that I wrote that add transparency to a
>>>System.Drawing.Image. When using this function on my webhost, I receive
>>>the error
>>>
>>> SecurityException: System.Security.Permissions.SecurityPermission
>>
>> Which line of code is causing the exception? Is it because the bitmap
>> operations are trying to write to a temporary path and your web host is
>> disallowing write access to the temp folder?
>
>
Re: Avoiding SecurityException: System.Security.Permissions.SecurityPermission
am 15.01.2008 22:27:27 von Nathan Sokalski
will come. Haggai
2:7, 8, 9, 10.
The calling of the Gentiles. Joel 2:28. Hosea 2:24. Deut. 32:21. Malachi
1:11.
716. Hosea 3.--Is. 42. 48. 44. 60. 61. last verse. "I foretold it long since
that they might know that it is I." Jaddus to Alexander.
717. Prophecies.--The promise that David will always have descendants. Jer.
13:13.
718. The eternal reign of the race of David, II Chron., by all the
prophecies, and with an oath. And it was not temporally fulfilled. Jer.
23:20.
719. We might perhaps think that, when the prophets foretold that the
sceptre should not depart from Judah until the eternal King came, they spoke
to flatter the people and that their prophecy was proved false by Herod. But
to show that this was not their meaning and that, on the contrary, they knew
well that this temporal kingdom should cease, they said that they would be
without a king and without a prince, and for a long time. Hosea 3:4.
720. Non habemus regem nisi Caesarem.[140] Therefore Jesus Christ was the
Messiah, since they had no longer any king but a stranger, and would have no
other.
721. We have no king but Caesar.
722. Daniel 2: "All thy soothsayers and wise men cannot shew unto thee the
secret which thou hast demanded. But there is a God in heaven who can do so,
and that hath revealed to thee in thy dream what shall be in the latter
days." (This dream must have caused him much misgiving.)
"And it is not by my own wisdom that I have knowledge of this secret, but by
the revelation of this same God, that hath revealed it to me, to make it
manifest in thy presence.
"Thy dream was then of this kind. Thou sawest a great i
Re: Avoiding SecurityException: System.Security.Permissions.SecurityPermission
am 15.01.2008 23:03:07 von Nathan Sokalski
the proof of our weakness, I shall conclude with
these two considerations...
73. But perhaps this subject goes beyond the capacity of reason. Let us
therefore examine her solutions to problems within her powers. If there be
anything to which her own interest must have made her apply herself most
seriously, it is the inquiry into her own sovereign good. Let us see, then,
wherein these strong and clear-sighted souls have placed it and whether they
agree.
One says that the sovereign good consists in virtue, another in pleasure,
another in the knowledge of nature, another in truth, Felix qui potuit rerum
cognoscere causas,[8] another in total ignorance, another in indolence,
others in disregarding appearances, another in wondering at nothing, nihil
admirari prope res una quae possit facere et servare beatum,[9] and the true
sceptics in their indifference, doubt, and perpetual suspense, and others,
wiser, think to find a better definition. We are well satisfied.
We must see if this fine philosophy has gained nothing certain from so long
and so intent study; perhaps at least the soul will know itself. Let us hear
the rulers of the world on this subject. What have they thought of her
substance? 394.[10] Have they been more fortunate in locating her? 395. What
have they found out about her origin, duration, and departure? Harum
sententiarum
Re: Avoiding SecurityException: System.Security.Permissions.SecurityPermission
am 15.01.2008 23:29:20 von Bob
than the
theatre. It is a representation of the passions so natural and so delicate
that it excites them and gives birth to them in our hearts, and, above all,
to that of love, principally when it is represented as very chaste and
virtuous. For the more innocent it appears to innocent souls, the more they
are likely to be touched by it. Its violence pleases our self-love, which
immediately forms a desire to produce the same effects which are seen so
well represented; and, at the same time, we make ourselves a conscience
founded on the propriety of the feelings which we see there, by which the
fear of pure souls is removed, since they imagine that it cannot hurt their
purity to love with a love which seems to them so reasonable.
So we depart from the theatre with our heart so filled with all the beauty
and tenderness of love, the soul and the mind so persuaded of its innocence,
that we are quite ready to receive its first impressions, or rather to seek
an opportunity of awakening them in the heart of another, in order that we
may receive the same pleasures and the same sacrifices which we have seen so
well represented in the theatre.
12. Scaramouch, who only thinks of one thing.
The doctor, who speaks for a quarter of an hour after he has said
everything, so full is he of the desire of talking.
13. One likes to see the error, the passion of Cleobuline, because she is
unconscious of it. She would be displeasing, if she were not deceived.
14. When a natural discourse paints a passion or an effect, one feels within
oneself the truth of what one reads, which was there before, although one
did not know it. Hence one is inclined to love him who makes us feel it, for
he has not shown us his own riches, but ours. And thus this benefit renders
him pleasing to us, besides that such community of intellect as we have wit
Re: Avoiding SecurityException: System.Security.Permissions.SecurityPermission
am 16.01.2008 01:17:35 von Leon Mayne
backwards, then more forward than ever, etc.
The tide of the sea behaves in the same manner; and so, apparently, does the
sun in its course.
356. The nourishment of the body is little by little. Fullness of
nourishment and smallness of substance.
357. When we would pursue virtues to their extremes on either side, vices
present themselves, which insinuate themselves insensibly there, in their
insensible journey towards the infinitely little; and vices present
themselves in a crowd towards the infinitely great, so that we lose
ourselves in them and no longer see virtues. We find fault with perfection
itself.
358. Man is neither angel nor brute, and the unfortunate thing is that he
who would act the angel acts the brute.
359. We do not sustain ourselves in virtue by our own strength, but by the
balancing of two opposed vices, just as we remain upright amidst two
contrary gales. Remove one of the vices, and we fall into the other.
360. What the Stoics propose is so difficult and foolish!
The Stoics lay down that all those who are not at the high degree of wisdom
are equally foolish and vicious, as those who are two inches under water.
361. The sovereign good. Dispute about the sovereign good.--Ut sis contentus
temetipso et ex te nascentibus bonis.48 There is a contradiction, for in the
end they advise suicide. Oh! What a happy life, from which we are to free
ourselves as from