开发者

Configuring ASP.NET application to always accept GET request from a particular IP address?

开发者 https://www.devze.com 2023-01-13 13:57 出处:网络
I have an application that\'s locked down using forms authentication. There are few nightly tasks I want to script that make get requests to, say, http://myapp.domain.com/NightlyTask ... I don\'t need

I have an application that's locked down using forms authentication. There are few nightly tasks I want to script that make get requests to, say, http://myapp.domain.com/NightlyTask ... I don't need any response, I just need it to accept a get request from a certain IP address. I realize you coul开发者_运维百科d spoof an IP address, etc. but I'm trying to make this dead simple.

Is there anyway I can setup the Web.config to unconditionally give access to a certain IP? Any other idea to approach this?

Again, long-term solution would be a service running Quartz or some other cron-like job handler. I'm not quite there yet, hoping for an interim solution. Thanks!


Not recommended for various security reasons but if you must, you can create your own authorization filter

public class AuthFilter : AuthorizeAttribute
{
    public override void OnAuthorization(AuthorizationContext filterContext)
    {
        if (filterContext.HttpContext.Request.UserHostAddress == "127.0.0.1")
            return;

        base.OnAuthorization(filterContext);
    }
}

you would substitute 127.0.0.1 for your ip and this would work.

0

精彩评论

暂无评论...
验证码 换一张
取 消