Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. using Socket is ASP.NET

using Socket is ASP.NET

Scheduled Pinned Locked Moved ASP.NET
tutorialcsharpasp-netquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shoaib khan
    wrote on last edited by
    #1

    i am trying to use socket in ASP.NET application. application is hosted on my own pc. when it tries to execute SendTo() function of Socket class i get exception that "An attempt was made to acess a socket in a way forbidden by its access permissions" please guide me how to use sockets in ASP.NET application. do i need to set some specific permission or what else??? thanks a lot!! Shoaib

    H 1 Reply Last reply
    0
    • S shoaib khan

      i am trying to use socket in ASP.NET application. application is hosted on my own pc. when it tries to execute SendTo() function of Socket class i get exception that "An attempt was made to acess a socket in a way forbidden by its access permissions" please guide me how to use sockets in ASP.NET application. do i need to set some specific permission or what else??? thanks a lot!! Shoaib

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      As the exception states, the problem is with code-access security. The ASPNET account (or whichever account ASP.NET is running as) was not granted the code-access permission (note, not domain / NT permission). This problem isn't easy to solve and requires that you read about code-access security in the .NET Framework SDK documents. I understand it well, but I can only explain so much (due to time, space, and avoiding confusion of the readers). Basically, code-access security limits code (attributed with security permission attribites) based on evidence for an assembly and a code-access policy. Evidence is information about the assembly and where it came from, such as a URL (http:, https:, file:, etc.), site (servername, either DNS- or WINS-resolved), its strong-name (assembly name, version, culture, and public key token; or, a subset of those), an optionally X.509 signature, etc. This evidence can be used either by the CLR (Common Language Runtime, the runtime for .NET) or by security permission attributes themselves to grant the right to execute (or remove the right, for that matter) to a caller or the entire call stack. A permission set defines various security permissions and a set of resources or actions those permissions grant. A code group defines a condition for code (such as a matching site or URL, or a matching strong name) to meet in order to have the permissions contained in the permission set assigned to the code group. So, the problem you're exhibiting is that your assembly or the ASP.NET user account is not being granted the appropriate permission sets (namely, the SocketPermission). This could be because you're not signing your assembly (see the sn.exe utility, and the AssemblyKeyFileAttribute documentation) or because the machine.config file doesn't give ASP.NET files full trust permissions (or, at least the SocketPermission). If your site is hosted by another company, you can ask them to allow your code the SocketPermission, but you should sign it as this opens your code up for new possibilities, including inreased security. Changes are, they may not unlesss you have a good reason because making socket connections from ASP.NET is dangerous (since it opens ASP.NET - and hence IIS and possibly the whole operating system with somewhat elevated privileges if not setup right) and time-consuming since a page can finish execution until the connection is closed (since HTTP - and hence ASP.NET - is stateless). I know this is

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups