使用asp.net和iis在geoserver中进行身份验证 [英] Authenticate in geoserver with asp.net and iis

查看:220
本文介绍了使用asp.net和iis在geoserver中进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道这是否是一个愚蠢的问题,但是如何将"asp.net"身份验证与openlayers结合"?

I don't know if this is a dumb question, but how can I "combine" the asp.net authentication with openlayers?

我创建了一个登录页面以在openlayers(在C#,服务器端)中进行身份验证,这是我的代码

I created a Login page to authenticate in openlayers (in c#, server side), this is my code

Uri uri = new Uri("http://"+username+":"+password+"@localhost:1979/geoserver/wms");
        if (uri.Scheme == Uri.UriSchemeHttp)
        {
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
            request.Method = WebRequestMethods.Http.Post;

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            StreamReader reader = new StreamReader(response.GetResponseStream()); string tmp = reader.ReadToEnd();
            response.Close();
            Response.Write(tmp);
        }

我不知道这是否是解决问题的正确方法,无论如何,如果达到我的目标(在geoserver中使用用户名和密码进行身份验证),我如何将这种身份验证与openlayers结合使用(位于用户端)( javascript)

I don't know if this is the right approach to resolve my problem, anyway if I reach my goal (authenticate with username and password in geoserver), how can I combine this authentication with openlayers, which is in user side (javascript)

预先感谢

推荐答案

要从javascript端对geoserever进行身份验证,必须在geoserver认证servlet(j_spring_security_check)中发布信息.尝试使用此登录功能:

To authenticate with the geoserever from javascript side, you must to make a post to the geoserver autentication servlet(j_spring_security_check). Try use this login function:

     function login (options) {
    // url del servlet del geoserver
    var url = options.server + "/geoserver/j_spring_security_check";
    // parametros para el login
    params = "username=" + options["user"] + "&password="
                + options["password"];

    var contentType = "application/x-www-form-urlencoded";
    //se inicializa la petición ajax
    var ajax = $.ajax({
        data : params,
        type : "POST",
        contentType : contentType,
        url : url
    });
    // se ejecuta cuando la peticion finaliza
    ajax.done(function() {

        if ($.cookie("JSESSIONID") != null && options && options.success) {
            options.success();
        }
    });
    // si ocurrio un error al realizar la peticion
    ajax.fail(function(data) {
        if (options && options.failure) {
            options.failure(data);
        }
    });
    // se ejecuta siempre al final de la petición, sin importar que esta
    // haya fallado
    ajax.always(function() {
        if (options && options.always) {
            options.always();
        }
    });
};

并使用这种方式

 login({
    user:"admin" //geoserver user
    password: "adminPassword", 
    server : "http://192.168.10.1:8080", //geoserver host
    success : function(){
        alert("Login OK!");
    },
    failure : function(){
        alert("Login fail!");
    }
});

这篇关于使用asp.net和iis在geoserver中进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆