9 Replies - 6286 Views - Last Post: 03 September 2011 - 03:56 AM Rate Topic: -----

#1 thesamy  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 54
  • Joined: 12-July 10

HttpListener start() access denied

Posted 02 September 2011 - 05:46 AM

hay, im learing about HttpListner and got some drills to do at home, so i set up the code and all but im not sure what im doing worng, i look at the msdn exmple and it look like i did every thing fine.


i tryed to do a debuging and run it in singel steping and got an Exception access denied
my firewall run on game mode and i didnt hed problems when i did a tcpServer and tcpClient

here is the code:

HttpListener listner = new HttpListener();
            listner.Prefixes.Add(@"http://127.0.0.1:50000/myFolder/");
            listner.Start();
           
            HttpListenerContext context = listner.GetContext();
            HttpListenerRequest requst = context.Request;
            HttpListenerResponse respons = context.Response;
            string theHTML = "<html> <head> wooo </head> <body> this is the body </body> </html>";
            respons.ContentLength64 = Encoding.UTF8.GetByteCount(theHTML);
            Stream stream = respons.OutputStream;
            StreamWriter writer = new StreamWriter(stream);
            writer.Write(theHTML);
            writer.Close();
            stream.Close();



(sorry for my english :))

Is This A Good Question/Topic? 0
  • +

Replies To: HttpListener start() access denied

#2 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: HttpListener start() access denied

Posted 02 September 2011 - 06:04 AM

Did you check that HttpListener.IsSupported == true?
Was This Post Helpful? 1
  • +
  • -

#3 thesamy  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 54
  • Joined: 12-July 10

Re: HttpListener start() access denied

Posted 02 September 2011 - 06:32 AM

View PostMomerath, on 02 September 2011 - 06:04 AM, said:

Did you check that HttpListener.IsSupported == true?


i just cheacked it and its supported.
i think is a firewall prolbem but i cant figure it out.
Was This Post Helpful? 0
  • +
  • -

#4 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: HttpListener start() access denied

Posted 02 September 2011 - 01:25 PM

Which line is throwing the error?
Was This Post Helpful? 1
  • +
  • -

#5 thesamy  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 54
  • Joined: 12-July 10

Re: HttpListener start() access denied

Posted 02 September 2011 - 03:51 PM

View PostMomerath, on 02 September 2011 - 01:25 PM, said:

Which line is throwing the error?


listner.start();
Was This Post Helpful? 0
  • +
  • -

#6 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: HttpListener start() access denied

Posted 02 September 2011 - 04:28 PM

I'd say it's a problem with your prefix, not your firewall. Does the directory exist?
Was This Post Helpful? 1
  • +
  • -

#7 thesamy  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 54
  • Joined: 12-July 10

Re: HttpListener start() access denied

Posted 03 September 2011 - 02:13 AM

View PostMomerath, on 02 September 2011 - 04:28 PM, said:

I'd say it's a problem with your prefix, not your firewall. Does the directory exist?


no i thoghot the prefix in just an adress to the "server" and then i send the user what i want?
cant the prefix used as a virtual folder?
Was This Post Helpful? 0
  • +
  • -

#8 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: HttpListener start() access denied

Posted 03 September 2011 - 02:53 AM

Is your program running with Administrator privilages? I found a closed bug report that says it must be run as an Administrator to work.
Was This Post Helpful? 1
  • +
  • -

#9 thesamy  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 54
  • Joined: 12-July 10

Re: HttpListener start() access denied

Posted 03 September 2011 - 03:14 AM

View PostMomerath, on 03 September 2011 - 02:53 AM, said:

Is your program running with Administrator privilages? I found a closed bug report that says it must be run as an Administrator to work.


yes that was the problem i started the program from the bin/realse/program.exe (run as admin) and it works thank u.
but there is a way to add this some code to tell the computure to run this as admin?
Was This Post Helpful? 0
  • +
  • -

#10 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: HttpListener start() access denied

Posted 03 September 2011 - 03:56 AM

Your program has a name, we'll call it MyProgram for this example. Everywhere you see MyProgram you'll have to replace with your programs name.

Create a file in the directory where your program resides. Put this in it:
<?xml version="1.0" encoding="utf-8" ?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <assemblyIdentity version="1.0.0.0"
      processorArchitecture="X86"
      name="MyProgram.exe"
      type="win32" />
    <description>Your Program Description</description>
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
        <security>
            <requestedPrivileges>
                <requestedExecutionLevel level="requireAdministrator" />
            </requestedPrivileges>
        </security>
    </trustInfo>
</assembly>


Rename the file MyProgram.exe.manifest

If you don't want to have to copy this file along with the exe, you can run the following command to imbed it in the executable:

mt -manifest MyProgram.exe.manifest -outputresource:MyProgram.exe
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1