How to use
If the sample has associated data, you will find that the sample's zip file includes a "data" folder alongside the language folders. However, you will need to update the sample to point to the location of the data once you have extracted all the files.
At design time
- Verify that the Web ADF for the .NET Framework is installed and functioning properly. For information on installing and configuring the Web ADF, consult the installation guide. To use the included SQL Server Express database, Microsoft SQL Server Express 2008 must be installed as well.
- In Windows Explorer, navigate to <ArcGIS Developer Kit install location>\Samples\ServerNET\Common_Security. This folder contains the sample's CSharp and VBNet folders.
- Open the folder of the language you're going to use—CSharp or VBNet—and copy the Common_Security_<language> folder to c:\inetpub\wwwroot. The <language> variable can be either CSharp or VBNet.
- Open the IIS Manager from Control Panel > Administrative Tools > Internet Information Services (IIS) Manager or Internet Information Services.
- In the console tree view on the left, navigate to Local Computer > Web Sites > Default Web Site, expand Default Web Site, right-click the Common_Security_<language> folder, and click Properties. The Properties dialog box opens.
- Click the Directory tab, click the Create button in the Application Settings section, then click OK to close the Properties dialog box.
- Start Microsoft Visual Studio 2008 or 2010 and open the Common_Security_<language><vs_version> solution (for example, Common_Security_CSharp2008.sln). The <vs_version> references the Visual Studio version of the solution, either 2008 or 2010.
- In Solution Explorer, right-click Default.aspx and select Set As Start Page.
- Open the Default.aspx page in Design view, open the properties window for the MapResourceManager control, and click the ellipsis next to the ResourceItems property. The ResourceItem Collection Editor dialog box opens.
- Add or change the MapResourceItem associated with a map service (ArcGIS Server, ArcIMS and so forth). This sample was created using the ArcGIS Server Internet service USA, based on the USA.mxd available in the <ArcGIS Developer Kit install location>\Samples\data\USA folder. Using this service avoids having to change the settings on the Web page.
- If an ArcGIS Server local resource was added in the previous step, set the run time identity of the Web application by following one of the next two steps. If not necessary, proceed to step 14.
- At design time, the identity of the user running Visual Studio is used to connect to an ArcGIS Server local data source. At run time, that identity is established by the Web application. Only one identity can be used to define access to the ArcGIS Server local data sources in a single Web application. This identity can be explicitly defined when building the Web ADF application in Visual Studio by right-clicking the Web project in Solution Explorer and selecting the Add ArcGIS Identity option. Enter the identity credentials that will be used to access ArcGIS Server local resources at run time. This information is added to the web.config file in a standard ASP.NET identity tag. If the Encrypt identity in web.config check box is checked, the identity tag will be encrypted; otherwise, the username and password are stored as clear text.
- Open the web.config file, add an <identity> element in <system.web>, set the impersonate attribute to true, and add a username and password attribute and set them to a valid user account. Ensure the account is in the agsusers and agsadmin account on the ArcGIS Server machine.
- If the USA map service described in step 10 is not used, follow the steps in the Use a different map service section below.
- Save the project.
- Add permissions for the user database by following the steps in the Add database permissions section below.
- In Visual Studio, click the Debug drop-down menu and click Start Debugging.
Use a different map service
- Open Default.aspx in Design view, click QueryAttributesTask1, click the smart tag (small arrow) in the upper right of the control, and click Edit the Query in the context menu. A dialog box opens.
- Modify the query so that it applies to a resource and layer in your application.
- Repeat steps 1 and 2 for QueryAttributesTask2 (in the LoginView control in the upper left of the page).
- Open the Default.aspx.cs or Default.aspx.vb code-behind page, find the variable layerToHide, and set it to the name of a layer that is present in a map resource (service) in the Web application.
- Save the project.
Add database permissions
- In Windows Explorer, navigate to the location of your Web site in C:\inetpub\wwwroot, right-click the App_Data folder, and choose Properties. The Properties dialog box opens.
- Click the Security tab, and click Add. The Select Users, Computers, or Groups dialog box opens.
- Add the ASPNET if using Windows XP and Network Service account if using Windows Server 2003 and 2008(use the Advanced button to find these accounts if necessary), and click OK.
- On the Security tab, highlight each of the ASPNET and Network Service accounts, check the Modify check box under Allow, and click OK. The security settings are saved.
At run time
- Browse to the viewer uniform resource locator (URL) (for example, http://localhost/Common_Security_CSharp). You'll be redirected to the login page.
- Enter a valid login. The included database has two users: manager1 (password manager1$) in the Managers group and staff1 (password staff1$), which is not in Managers group. Upon successful login, you are redirected to the main default.aspx page. If logged in as a user in the Managers role, the items described in the Additional information section below are available. If logged in as a user not in Managers, the page removes a layer, the Map Info tool, and the two tasks from the page.
- Interact with the map and other items on the page. The Map Info tool, if available, displays fields and names of vector layers in the map services (including graphics layers, if present after using tasks).
- Use the Change Password link to modify the current user's password.
- Click Log Off. You are returned to the login page. You can log in again with a different account if desired.
- Use the Create User link to create a new account. The new account is not added to any role by default, so it cannot access the optional content that is available only to the Managers role. You can use the Web Site Administration Tool to add the user to a role.
Additional information
In this sample, if the user is not in the designated Managers role (group), the following items are removed from the page:
- Map layer—The highways layer is hidden on the map and its entry removed from the Toc control
- Toolbar item—The custom Map Info command is removed from the toolbar
- Task—Two QueryAttributesTask controls are removed from the page
The map layer, toolbar item, and one of the QueryAttributesTask items are removed in the PreRenderComplete event of the Default.aspx code-behind page. The second QueryAttributesTask is hidden using an ASP.NET LoginView control. A role view template is defined for the Managers role, and the task is placed inside this template so that the task appears only when a member of the Managers role is logged in. The page also uses the following ASP.NET login controls to facilitate its work:
- Login control—Used in Login.aspx to log in users.
- LoginName control—Used in Default.aspx to display the logged-in username.
- LoginStatus control—Used in Default.aspx to display a log-out hyperlink.
- CreateUserWizard control—Used in CreateUser.aspx to enable new users to create an account. A hyperlink from the login page leads to this page.
- ChangePassword control—Used in ChangePassword.aspx to allow logged-in users to change their password. A hyperlink from the Default.aspx leads to this page.
This sample uses a SQL Server Express database to store users and roles. The database was created using the Web Site Administration Tool (WSAT). WSAT can be used to edit the users and roles for this sample. To access WSAT, open the Web site in Visual Studio (or Visual Web Developer Express), then select Website-ASP.NET Configuration. WSAT opens in a browser window. Choose the Security category to manage users, roles, and access rules for the Web site.
The included database has two users: manager1 (password: manager1$) and staff1 (password: staff1$). The manager1 account is a member of the Managers role, so this user can see all content on the page. The staff1 user is not in Managers and has items hidden as described above. Users and roles can be edited with WSAT. Database permission issues are described in the At design time section above.
Common_Security_CSharp\Default.aspx | User interface for the Web application. |
Common_Security_CSharp\Default.aspx.cs | Code behind the user interface. |
Common_Security_CSharp\Login.aspx | User interface for the initial login page. |
Common_Security_CSharp\Login.aspx.cs | Code behind the user interface for the login page. |
Common_Security_CSharp\App_Code\GetMapInformation.cs | Contains implementation of the custom command for the Map Info button on the toolbar. |
Common_Security_VBNet\Default.aspx | User interface for the Web application. |
Common_Security_VBNet\Default.aspx.vb | Code behind the user interface. |
Common_Security_VBNet\Login.aspx | User interface for the initial login page. |
Common_Security_VBNet\Login.aspx.vb | Code behind the user interface for the login page. |
Common_Security_VBNet\App_Code\GetMapInformation.vb | Contains implementation of the custom command for the Map Info button on the toolbar. |
Download the files for all languages