Showing posts with label arcgis server. Show all posts
Showing posts with label arcgis server. Show all posts

Thursday, October 22, 2009

How to trigger some javascript (client-interaction) the very first time the page is requested in an ESRI .NET web ADF based web application?


Since the esri .net web adf is based on asp.net ajax we can leverage the client application and page lifecycle to trigger activities in different phases of the lifecycle. 
The below illustrates what happens during first page load, partial page postback, and browser close/moving away:
 A. During first initial page request: (1st time the page is loaded or refreshed)
APP_init
APP_load
APP_page_Load 

Notes: The init event of the Application instance is raised only one time for the life of the page in the browser. It is not raised for subsequent asynchronous postbacks. During an initial request, no PageRequestManager events are raised.
B. During Asynchronous postback (aka partial page postback, ajax request using asp.net ajax)
PRM_init_request
PRM_begin_request
WRM_invoking_request
WRM_completedRequest
PRM_page_loading
PRM_page_loaded
APP_load
PRM_end_request 

C. During browser close or browsing away from the page:
PRM_init_request
APP_unload

Where
APP = Sys.Application object
PRM = Sys.WebForms.PageRequestmanager
WRM = Sys.Net.WebRequestManager


1)       1) Create a file and place it  as follows: YourWebApp/javascript/ocgis.js
//contents of file
if (typeof myns== 'undefined') { myns = {}; }
myns.didOnce = false
myns.initAppEventHandler = function(sender) {
                myns.loadAppEventHandler();
}

myns.loadAppEventHandler = function(sender) {
    var prm = Sys.WebForms.PageRequestManager.getInstance();
                if (!ocgis.didOnce) {
                    alert("TODO: initiate things and show panel using javascript....");
                    myns.didOnce = true;
                }
} 

2)       In the default.aspx page, Insert the below right before </body> , i.e. end of body tag
<script language="javascript" type="text/javascript" src="javascript/myns.js" ></script>
<script
language="javascript" type="text/javascript">
                Sys.Application.add_init(myns.initAppEventHandler);
                Sys.Application.add_load(myns.loadAppEventHandler);
</script>  


The diagram below does a great job of showing the events from the 3 main objects in a nice sequence diagram:

Saturday, October 17, 2009

Direct Connect to ArcGIS ArcSDE through a firewall

Direct Connect (DC) is now the ESRI recommended connection method to connect to an ArcSDE database running on SQL Server 2000/2005/2008, Oracle etc databases. This is recommended for various reasons concerning efficiency, performance, memory and scalability. As opposed to 'Application connect', direct connect does not spawn a process (giosrvr) on the ArcSDE server and does not require the arcsde (giomgr) services to be listening on designated ports for geodatabases. Not only that, but DC (running on SQL Server) requires only one port to communicate to all geodatabases inside ArcSDE - the sql server port, usually 1433. So if there's a firewall between the ArcSDE server and ArcGIS server/desktop, then opening port 1433 would suffice. One more great reason to use DC.

To add even more, ArcGIS 9.3, 9.3.1 and 9.2 SP5 can backward connect to 9/9.1/9.2 running on most databases.The following rules are used to govern how connections between different versions of ArcGIS clients and geodatabases operate:
  • Current releases of ArcGIS clients can connect to and use previous releases of the geodatabase. For example, an ArcGIS 9.1 client can connect to and use an ArcGIS 9 geodatabase.
You should be aware of the following, though:
    • If the ArcGIS client is using a direct connection to an ArcSDE 9.2 or prior geodatabase, connections cannot be made from the newer client to the older geodatabase. For example, an ArcGIS 9.2 client cannot make a direct connection to an ArcSDE 9.1 geodatabase.
    • Functionality specific to the current release is not available when connecting to a previous release of the geodatabase. For example, if you connect from an ArcGIS 9.1 client to an ArcGIS 9 personal geodatabase, you will only have access to functionality available at ArcGIS 9.
  • Previous releases of ArcGIS clients cannot connect to and use geodatabases created with later versions of ArcGIS. For example, an ArcGIS 9.1 client cannot connect to and use an ArcGIS 9.2 geodatabase.
The exceptions to this rule are as follows:
    • ArcGIS 9.2 Service Pack 5 (SP5) can open and edit a 9.3 geodatabase. Be aware, though, that functionality specific to the current geodatabase release is not available when connecting from a previous release of the client application.
    • ArcGIS 9 can open and edit a 9.1 geodatabase.




Client release
Personal geodatabase release
File geodatabase release
ArcSDE geodatabase using a direct connection
ArcSDE geodatabase using an ArcSDE service connection
8.3
8.3
NA
8.3
8.3
9
9, 9.1
NA
9
9, 9.1
9.1
9, 9.1
NA
9.1
9, 9.1
9.2
9, 9.1, 9.2
9.2
9.2
9, 9.1, 9.2
9.2 SP5
9, 9.1, 9.2, 9.3
9.2, 9.3
9.2, 9.3
9, 9.1, 9.2, 9.3
9.3
9, 9.1, 9.2, 9.3, 9.3.1
9.2, 9.3, 9.3.1
9.3, 9.3.1
If client has pre-9.3 geodatabase direct connect files* installed, can connect to 9, 9.1, and 9.2

9, 9.1, 9.2, 9.3, 9.3.1
9.3.1
9, 9.1, 9.2, 9.3, 9.3.1
9.2, 9.3, 9.3.1
9.3, 9.3.1
If client has pre-9.3 geodatabase direct connect files* installed, can connect to 9, 9.1, and 9.2

9, 9.1, 9.2, 9.3, 9.3.1

Sources:


Tuesday, December 23, 2008

Authentication/Login based ArcGIS ADF Task


How do you use the ArcGIS Server .net ADF Task Framework to create a Task which will take into account whether an user is authenticated or logged in? Easy. Basically, we can extend any ADF task or override the Render method to render only when logged in. We use a session variable to indicate if user is logged in. The benefits of this is that we can use any type of login mechanism, asp.net's login control, or anything else, as long as we set a session variable to indicate login status when the user is logged in. If we use asp.net's login control, we can set an eventHandler for loggedIn event to set the session variable. The code below extends the out of the box SearchAttributesTask from the ADF so that it renders only when our user is logged in. Now note that this customTask is not a full blown task, it is just a class that extends an existing task, as simple as that.
Imports Microsoft.VisualBasic
Imports ESRI.ArcGIS.ADF.Tasks
Imports log4net
Imports ESRI.ArcGIS.ADF.Web.UI.WebControls

Namespace WebMapApp
    Public Class LoginBasedSearchAttributesTask
        Inherits SearchAttributesTask

        Private Shared ReadOnly logger As ILog = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)


        Public Overrides Sub ExecuteTask()
            MyBase.ExecuteTask()
        End Sub

        Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
            MyBase.OnLoad(e)
        End Sub

        Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)

            Dim Session As HttpSessionState = HttpContext.Current.Session
            Dim isRenderObj As Object = Session("loggedInSuccess")
            If (isRenderObj IsNot Nothing) Then
                Dim isRender As Boolean = CType(isRenderObj, Boolean)
                If (isRender) Then
                    MyBase.Render(writer)
                Else
                    writer.RenderBeginTag("div")
                    writer.AddStyleAttribute(HtmlTextWriterStyle.Color, "red")
                    writer.AddStyleAttribute(HtmlTextWriterStyle.FontSize, "9pt")
                    writer.Write("You are required to login to use this task, to login go to the CIP menu and then Login")
                    writer.RenderEndTag()
                    Return
                End If
            End If

        End Sub

    End Class
End Namespace

There's one more thing left, we need to write the declarative code inside default.aspx for this CustomTask. We should note that the Render() method is called during partial page postbacks or full postbacks, and not during callbacks. So this approach won't work without a asp.net ajax ScriptManager (e.g. in ADF9.2 apps). We wrap our task inside an ajax:UpdatePanel, and then put that ajax:UpdatePanel inside another esri:FloatingPanel. Note, that the updateMode is set to conditional for efficiency reasons, minimizing http response from the server on every postback. Because of this we need to manually update the UpdatePanel, so when the user logins, the codebehind page should call SearchCIPUP.update(), so that this task is re-rendered. Because our custom task is inside another FloatingPanel, we should remember to disable the visual elements, e.g. titlebar, closebutton, borders etc of the inner-task, as shown below.
        
        
            
                
                    
                        
                    
                                
            
        
    

The CSS code:
        .SearchCIPTaskTitleBarCSS
        {
         display:none;
         visibility:hidden;
         width:0px;
         height:0px;
        }
        .SearchCIPTaskCSS
        {
         height:100%;
         width:100%;
         border: none 0px transparent;
         position: relative;
         background-color:White;
        }
There you go, it's as simple as that. It works beautifully.