By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,665 Members | 1,251 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,665 IT Pros & Developers. It's quick & easy.

System.Security.SecurityException

P: n/a
hi

I'm attempting to build an app then sends a request to a URL and reads the
response it works fine on my test site but when I connect to a real system I
get the text below, I guess its responding to a request from the remote end
if so how do I either tell it to ignore the request and just send the url or
set what its looking for?

If type the same url in the address bar of IE it works without requesting
any permissions!

the code used to send the request is at the bottom.

Help!!!!

************** Exception Text **************

System.Security.SecurityException: Request for the permission of type
System.Net.WebPermission, System, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089 failed.

at System.Security.CodeAccessSecurityEngine.CheckHelp er(PermissionSet
grantedSet, PermissionSet deniedSet, CodeAccessPermission demand,
PermissionToken permToken)

at System.Security.CodeAccessSecurityEngine.Check(Per missionToken
permToken, CodeAccessPermission demand, StackCrawlMark& stackMark, Int32
checkFrames, Int32 unrestrictedOverride)

at System.Security.CodeAccessSecurityEngine.Check(Cod eAccessPermission
cap, StackCrawlMark& stackMark)

at System.Security.CodeAccessPermission.Demand()

at System.Net.HttpRequestCreator.Create(Uri Uri)

at System.Net.WebRequest.Create(Uri requestUri, Boolean useUriBase)

at System.Net.WebRequest.Create(String requestUriString)

at myControl1.myControl.LoadURL(String Url)

at myControl1.myControl.Button1_Click(Object sender, EventArgs e)

at System.Windows.Forms.Control.OnClick(EventArgs e)

at System.Windows.Forms.Button.OnClick(EventArgs e)

at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)

at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)

at System.Windows.Forms.Control.WndProc(Message& m)

at System.Windows.Forms.ButtonBase.WndProc(Message& m)

at System.Windows.Forms.Button.WndProc(Message& m)

at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)

at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)

at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)

the code that is sending the request follows and URL is set to the following
format http://awebsite/abc?id=1234?data=12345

Public Function LoadURL(ByVal Url As String) As String

Try

Dim wrq As WebRequest = WebRequest.Create(Url)

Dim wrp As HttpWebResponse = _

DirectCast(wrq.GetResponse(), HttpWebResponse)

Dim sr As New StreamReader(wrp.GetResponseStream)

Dim Text As String = sr.ReadToEnd()

wrq.Timeout = 30

Return Text

sr.Close()

wrp.Close()

Catch e As WebException

Console.WriteLine(e.Message)

Return e.Status.ToString

If e.Status = WebExceptionStatus.ProtocolError Then

Console.WriteLine("Status Code : {0}", CType(e.Response,
HttpWebResponse).StatusCode)

Console.WriteLine("Status Description : {0}", CType(e.Response,
HttpWebResponse).StatusDescription)

End If

End Try

Return Text

End Function
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Problem was that the site I was posting to was different to the hosting
site!

I needed to add permissions

control panel - Administrative Tools - Microsoft .NET Framework 1.1
Configuration - Runtime Security Policy - Machine - Code Groups - All_Code -
Trusted_Zone
Then Right-click Trusted_Zone, and then click New

Name = test

Condition = Zone

Zone = Trusted

Permission = full trust

Click Finish

Add hosting site to trusted sites

"Adrian" <Ad****@nospamhotmail.com.uk> wrote in message
news:cs**********@sparta.btinternet.com...
hi

I'm attempting to build an app then sends a request to a URL and reads the
response it works fine on my test site but when I connect to a real system
I get the text below, I guess its responding to a request from the remote
end if so how do I either tell it to ignore the request and just send the
url or set what its looking for?

If type the same url in the address bar of IE it works without requesting
any permissions!

the code used to send the request is at the bottom.

Help!!!!

************** Exception Text **************

System.Security.SecurityException: Request for the permission of type
System.Net.WebPermission, System, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089 failed.

at System.Security.CodeAccessSecurityEngine.CheckHelp er(PermissionSet
grantedSet, PermissionSet deniedSet, CodeAccessPermission demand,
PermissionToken permToken)

at System.Security.CodeAccessSecurityEngine.Check(Per missionToken
permToken, CodeAccessPermission demand, StackCrawlMark& stackMark, Int32
checkFrames, Int32 unrestrictedOverride)

at System.Security.CodeAccessSecurityEngine.Check(Cod eAccessPermission
cap, StackCrawlMark& stackMark)

at System.Security.CodeAccessPermission.Demand()

at System.Net.HttpRequestCreator.Create(Uri Uri)

at System.Net.WebRequest.Create(Uri requestUri, Boolean useUriBase)

at System.Net.WebRequest.Create(String requestUriString)

at myControl1.myControl.LoadURL(String Url)

at myControl1.myControl.Button1_Click(Object sender, EventArgs e)

at System.Windows.Forms.Control.OnClick(EventArgs e)

at System.Windows.Forms.Button.OnClick(EventArgs e)

at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)

at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)

at System.Windows.Forms.Control.WndProc(Message& m)

at System.Windows.Forms.ButtonBase.WndProc(Message& m)

at System.Windows.Forms.Button.WndProc(Message& m)

at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)

at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)

at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)

the code that is sending the request follows and URL is set to the
following format http://awebsite/abc?id=1234?data=12345

Public Function LoadURL(ByVal Url As String) As String

Try

Dim wrq As WebRequest = WebRequest.Create(Url)

Dim wrp As HttpWebResponse = _

DirectCast(wrq.GetResponse(), HttpWebResponse)

Dim sr As New StreamReader(wrp.GetResponseStream)

Dim Text As String = sr.ReadToEnd()

wrq.Timeout = 30

Return Text

sr.Close()

wrp.Close()

Catch e As WebException

Console.WriteLine(e.Message)

Return e.Status.ToString

If e.Status = WebExceptionStatus.ProtocolError Then

Console.WriteLine("Status Code : {0}", CType(e.Response,
HttpWebResponse).StatusCode)

Console.WriteLine("Status Description : {0}", CType(e.Response,
HttpWebResponse).StatusDescription)

End If

End Try

Return Text

End Function

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Browse more Visual Basic .NET Questions on Bytes