SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    May 2008
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    allow ip address to access my webmethod

    hi,

    I have hosted a webservice in my server. I have list of ip(4) from where i will get the request. I don't want others to access my webservice. How do i acheive this? Is it possible through code? Please give a solution.

    Regards,
    Senthilkumar

  2. #2
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,625
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Aside from the fact that IP-based restrictions are pretty insecure as IP headers are easily forged with the right toys, it is pretty easy.

    Method #1: just let IIS handle it by only allowing the specified sites to access your app
    Method #2: handle it in the application layer with a custom HTTP module

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2009
    Location
    England
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1. Can be set in IIS if this is running on its on server, virtual server. This would be the best solution as stops hackers accessing near the top of the chain.



    2. C# code
    <code>
    if(Context.Request.UserHostAddress == '192.168.0.0' || Context.Request.UserHostAddress == '192.168.0.1')
    {
    // Code for webservice
    }
    else
    {
    // Your not allowed
    Context.Response.Status = 403; // Forbidden
    }
    </code>



    3.
    Please give a solution.
    Many people in many cultures will find it offensive if you tell them what to do, espcially when your the one asking for help. Thier attitude will be, if you want them to help you, you get it in any form they see fit. Hope this helps you for the future.
    Last edited by SirKilljoy; Apr 6, 2009 at 07:55. Reason: Staus = 403 not 404, btw I didn't see wwb_99 post when I replied. So don't wish to sound like I disagree with him in anyway


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •