Re: System.Security.SecurityException

From: Adrian (Adrian_at_nospamhotmail.com.uk)
Date: 01/21/05


Date: Fri, 21 Jan 2005 19:27:27 +0000 (UTC)

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" <Adrian@nospamhotmail.com.uk> wrote in message
news:csoe4b$n28$1@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.CheckHelper(PermissionSet
> grantedSet, PermissionSet deniedSet, CodeAccessPermission demand,
> PermissionToken permToken)
>
> at System.Security.CodeAccessSecurityEngine.Check(PermissionToken
> permToken, CodeAccessPermission demand, StackCrawlMark& stackMark, Int32
> checkFrames, Int32 unrestrictedOverride)
>
> at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission
> 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(MouseEventArgs 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(Message& 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
>
>