Infrastructure Map Server Forum
Welcome to Autodesk’s Infrastructure Map Server Forums. Share your knowledge, ask questions, and explore popular Infrastructure Map Server topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

An unclassified exception occurred

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
soudemans
2128 Views, 4 Replies

An unclassified exception occurred

Hi,

I have a simple form with some text boxes and a couple of buttons. I select a feature and open the form using build in MapGuide Studio functionality. The Page_Load event works and populates the txtFlushedBy textbox with the hydrant number. Then when I click on the cancel button which is supposed to do something fairly innert like set the same textbox to "Hello" I get the "An unclassified exception occurred" error and it sites the "Dim userInfo As MgUserInformation = New MgUserInformation(sessionId)" in the Page_Load event as the source of the error. Anyone have any ideas what the problem is?

Thanks
Code below:

Imports OSGeo.MapGuide
Imports System.Xml
Imports System.Data
Imports System.Data.SqlClient

Partial Class App_Forms_HydrantFlushHistForm
Inherits System.Web.UI.Page

'_________________________________________________________________________________________________
Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click

txtFlushedBy.Text = "Hello"

End Sub

'_________________________________________________________________________________________________
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' InvokeURL sends the data as a POST with the following form fields
Dim sessionId As String = Request.Form("SESSION")
Dim mapName As String = Request.Form("MAPNAME")
Dim selectionXml As String = HttpUtility.UrlDecode(Request.Form("Key"))
Dim sHydrantNo As String

' Initialize MapGuide
MapGuideApi.MgInitializeWebTier(Request.MapPath("/mapguide") + "webconfig.ini")

' Open site connection
Dim userInfo As MgUserInformation = New MgUserInformation(sessionId)

Dim siteConnection As New MgSiteConnection
siteConnection.Open(userInfo)

' Get the current map
Dim resourceService As MgResourceService = siteConnection.CreateService(MgServiceType.ResourceService)
Dim map As New MgMap(siteConnection)
map.Open(resourceService, mapName)

' Get the current selection
Dim selection As New MgSelection(map, selectionXml)

For Each layer As MgLayer In selection.GetLayers
' Get number of features for this layer (if you need it)
Dim count As Integer = selection.GetSelectedFeaturesCount(layer, layer.FeatureClassName)

' Read the feature data
Dim featureReader As MgFeatureReader = selection.GetSelectedFeatures(layer, layer.FeatureClassName, False)
While featureReader.ReadNext()
sHydrantNo = featureReader.GetString("HydrantNo")
txtFlushedBy.Text = sHydrantNo
'txtFlushedBy.Text = "Cancel"

'txtFlushedBy.text = sHydrantNo
End While
featureReader.Close()
featureReader.Dispose()
Next
End Sub

End Class
4 REPLIES 4
Message 2 of 5
sasyomaru
in reply to: soudemans

Hello,
Did you use the Fusion web layout or basic web layout?
Did you use the open source version or enterprise version?

First, make sure all the dlls you need is in your web site (I think you're using .net API, if so, make sure that all the dlls in "mapviewernet/bin" are in your web site, not just the one you referenced to, especially those with suffix UnmanagedApi).
Second, debug to make sure the webconfig.ini you're referenced to does exist and sessionId is not null or empty string.
Message 3 of 5
soudemans
in reply to: soudemans

Thanks for your inquiry.
1. We are using basic web layout.

2. This question is a bit tricky and requires some explanation. We are adding functionality to an existing website, the website in question is Open Source, however we have replicated the website on an Autodesk Mapguide Enterprise Server (enterprise version as you called it) We recognize that this could be a potential source for problems and are in the process of moving the site to an open source server.

3. (First) The dlls in mapviewernet/bin are part of the website by virtual reference and I found only one file suffixed UnmanagedApi which was MapGuideUnmanagedApi.dll

4. (Second) We think the right webconfig.ini is being referenced

5. (Second) The SessionID is not null initially, but when I click a button on the form a call-back is issued which evaluates the page_load event a second time, which returns a null session ID. I have received a suggestion to resolve the issue as follows:

The issue is this: The first call to this page is coming from the AJAX viewer as a POST, and contains those three parameters that are read at the beginning of the Page_Load function. Subsequent requests for this page (like when you click a button) come from the page itself, and do not have those parameters by default.

The solution is to add three hidden fields to your page called SESSION, MAPNAME, and Key, and populate those with the parameter values you get from Request.Form. Then the next time the page is submitted, it will get those parameters using Request.Form() calls you already have.

I tried this and eliminated the original error, but caused a new error “A potentially dangerous Request.Form value was detected” because the “Key” value is an xml string. The suggested answer for this error is to set ValidateRequest="false" which I did in the form’s aspx file header. (to be honest my coworkers and I think that this probably is a truly bad idea especially since you would have to do this for every form in your application, not to mention the possible security risks you would expose your website to.)

The way things stand right now we have a solution, BUT I think it is only about half baked and I am still searching for another.
Message 4 of 5
sasyomaru
in reply to: soudemans

Hello, Soudemans

I can see no improvement for the solution of null session ID, which is also the best way I can thought of.

About the validate error, if you want to use it in many pages, there are two ways of doing this:

1. Set the ValidateRequest="false" in web.config. It should be like this:
<configuration>
<system.web>
<pages validateRequest= "false " />
</system.web>
</configuration>


This configuration will be automatically used in every pages. However, this is not a good solution. Because in the validate process of the asp.net, there are a lot of things to validate and it's not a good way to close them all.

2. Write a error handling function in the page that need to handle validate exception, or the global page which will handle error for all pages. The error handling function should be like this (sorry to use C# because my knowledge about VB is very limited):

protected void Page_Error(object sender, EventArgs e)

{

Exception ex = Server.GetLastError();

if (ex is HttpRequestValidationException)

{

//Your code to handle the validate exception, for example, write a log.

Server.ClearError(); // So that the exception will not becomes an application error.

}

}

Hope this will help you. Edited by: sasyomaru on May 31, 2010 10:05 AM
Message 5 of 5
soudemans
in reply to: soudemans

I think we have an answer – at least I have not seen the error since I implemented this fix.  The original problem was in handling the SessionID, MapName and SelectionXML variables which you need to refer to your mapguide session, map name and selection set.  The solution involved capturing the three variables in their “ViewState” counterparts and then getting the values from the ViewState rather than the Request.Form().  Code is included in a jpg.  Since I am fairly new at this and probably should not be making any absolute recommendations, I would invite any discussion by members with better solutions Smiley Happy

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report