目的:
1.arcgis server9.2 ADF实现根据用户权限不同对地图功能进行控制。
准备工作:
1.用ArcGis Server Manager或者ArcCatalog发布一个叫usa的Map Service,并且把这个Service启动起来。
2.找到DeveloperKit\SamplesNET\Server\Web_Applications目录下的Common_SecurityCSharp.zip。
开始:
1.Esri提供的范例是用MDF数据库和微软提供的Membership进行用户的创建登录管理等,这里为了方便没有用数据库了就写死2个权限不同的用户admin/admin,user/user。
2.新建名为Security的ASP.NET Web应用程序,然后新建Login.aspx页面用来进行用户的登录,一个用户名输入框;一个密码输入框;一个登录按钮就可以了非常的简单了不详细说明了,具体看一下登录代码:
1
//登录按钮的事件
2
protected void Button1_Click(object sender, EventArgs e)
3
}
3.然后在Default.aspx页面中添加一个Label1用来显示用户登录信息,然后在cs代码中添加方法Page_PreRenderComplete,在这个方法中判定用户是否登录没有登录就跳到Login.aspx页面。
2
3
{
if (Session["user"] == null)
{
Response.Redirect("Login.aspx");
}
else
{
Label1.Text = " 登录用户:" + Session["user"].ToString() + " 用户组:" + Session["type"].ToString();
}
}
5.在Toolbar1中添加一个Command,用来获取地图和图层的信息,添加一个<div ></div> 用来显示获取的信息。当只有管理组的时候才可以使用这个功能。具体的定义如下:
1
<esri:Command ClientAction="" DefaultImage="~/identify_1.gif" JavaScriptFile="" Name="GetMapInfo" ServerActionAssembly="Security" ServerActionClass="Security.GetMapInformation" Text="Info" ToolTip="Get information about the map layers" />
GetMapInformation的代码如下:
1
namespace Security
2
6.接下来用QueryAttributesTask在做一个通过选择states图层的STATE_NAME进行属性查询的功能,也只有是管理员组的用户才能用这个功能。2
7.在页面上添加Menu1、TaskResults1、MapResourceManager1,把MapResourceManager1的BuddyControl设为Menu1,在MapResourceManager1添加一个QueryAttributesTask1,把QueryAttributesTask1的TaskResultsContainers-BuddyControl的属性设为TaskResults1,点击QueryAttributesTask1的PredefinedQuery属性栏弹出对话框进行设置,设置如下:Resource Manager:MapResourceManager1;Resource:MapResourceItem0;Layer:states;Label Text:Name;Associated Field:STATE_NAME;Operator:=;勾上Show Pick List并且点击Get Sample Values按钮添加选择项。
8.接下在做一个查询人口大于3000000的国家功能,添加QueryAttributesTask2,TaskResultsContainers-BuddyControl的属性设为TaskResults1,PredefinedQuery属性设置如下:Resource Manager:MapResourceManager1;Resource:MapResourceItem0;Layer:counties;Label Text:Name;Associated Field:pop1999;Operator:>;Default value:3000000。
9.这样功能就开发完成了可以运行查看一下效果,接下来要根据登录用户的权限进行功能的控制。
10.当用户属于管理员组的时候可以在Map1和Toc1中显示ushigh图层,当用户不属于管理员组是不显示ushigh图层,在Page_PreRenderComplete方法中添加如下代码:
1
//要隐藏的图层名称
2
private string layerToHide = "ushigh";
3
4
protected void Page_PreRenderComplete(object sender, EventArgs e)
5
11.这样可以用不同的用户登录看看效果了。2
3
4
5
12.接下来实现当用户属于管理员组的时候可以使用GetMapInfo按钮和QueryAttributesTask1,当用户不属于管理员组时不能使用GetMapInfo按钮和QueryAttributesTask1。具体代码如下: