Check out this document for the list of IIS server variables:
http://msdn.microsoft.com/en-us/library/ms524602.aspx
REMOTE_ADDR will give you the remote IP address. You could also try
REMOTE_HOST to get the translated DNS name, but that might not be as
reliable. Try it and see if that works for your needs.
I don't have source code for unfortunately. I think the Authenticate event
is likely to be the way to go with this as it will allow forms
authentication to work normally first and then give your code a crack to
handle this condition afterward.
You could either take the approach to generate a fixed authenticated user
context based on a match to your source IP and have this user participate in
authorized access to the site or you could take the approach of allowing
matches to this source IP access the site anonymously from the Context.User
perspective.
To do the former, you should just need to generate a valid IPrincipal object
and set that in Context.User and then potentially generate a forms auth
cookie for that user to handle subsequent requests. So, the first thing to
check in the Authenticate event is whether the forms auth module has already
authenticated a user.
If you want requests that match this source IP to access the site
anonymously, you can just call HttpContext.SkipAuthorization. This will
instruct the UrlAuthorizationModule to skip this request and allow anonymous
access to whatever was requested.
I don't know enough about the details of your system to know which approach
would be preferable.
--
Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
"Larry Smith" <no_spam@_no_spam_.com> wrote in message
news:...
> >I think what I would probably try to do is have a piece of code that
> >basically integrates with the existing forms login system and generates a
> >forms login ticket/cookie directly based on the source IP server
> >variable.
>>
>> Perhaps something that runs in BeginRequest or Authenticate like an
>> HttpModule or Global.asax handler that generates a forms auth cookie via
>> SetAuthCookie and sets a valid IPrincipal in Context.User would be
>> sufficient. It should effectively provide SSO for clients presenting the
>> required source IP and will challenge for forms auth as normal for those
>> that do not.
>>
>> I also tend to agree with Bruce's parallel comment that providing a
>> non-forms auth method for accessing a page designed for programmatic
>> access like a web service is probably a good idea.
>
> Thanks for the feedback (to both of you). Do either of you know of a link
> with an example I can extrapolate from. I don't need a lot of
> hand-holding. Also, how do you get hold of the calling domain in code (or
> their IP address at the very least). Thanks.
>