I am facing problem while making web request by WebClient.
I am making request to google map geocode apge to findout the longitude and latitude of particular address.
Here is my code to do that :
Dim QueryString As String
Dim responseText As String = ""
Dim WC As New Net.WebClient
Dim SR As IO.StreamReader
QueryString = "?q=" & getValidAddressString() & "&output=csv&key=" & ConfigurationManager.AppSettings("GeoCodeKey")
Dim redirectURL As String = ConfigurationManager.AppSettings("GeoCodeURL") & QueryString
SR = New IO.StreamReader(WC.OpenRead(redirectURL))
responseText = SR.ReadToEnd()
SR.Close()
processResponseText(responseText)
The strange thing is that for same address string, the code is working without any problem in one page. While the same code(have copy pasted) in another page is throwing the following error :
Illegal characters in path.
Exception Details: System.ArgumentException
at System.Security.Permissions.FileIOPermission.HasIllegalCharacters(String[] str)
at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String[] pathList, Boolean checkForDuplicates, Boolean needFullPath)
at System.IO.Path.GetFullPath(String path)
at System.Net.WebClient.GetUri(String path)
at System.Net.WebClient.DownloadData(String address)
at KG.GeoCodeHelper.Page_Load(Object sender, EventArgs e) in
Kiran BeladiyaPosted Apr 30, 2008, 5:40 AM
For your information I am sending one of URL which is used in my webclient request. It is :
http://maps.google.com/maps/geo?q=4610 N Fairfax Drive,Arlington,VA,22203,United States of America&output=csv&key=ABQIAAAARTl5NX7JU30LDNhqaIGTBBT2yXp_ZAY8_ufC3CFXhHIE1NvwkxTi80XdAA-lXaRCoNVg8QSDNkrBMA
Please note the key is what i am using for my localhost, probably you will need your own google map api key.
So the code becomes now :
Dim redirectURL As String = "http://maps.google.com/maps/geo?q=4610 N Fairfax Drive,Arlington,VA,22203,United States of America&output=csv&key=ABQIAAAARTl5NX7JU30LDNhqaIGTBBT2yXp_ZAY8_ufC3CFXhHIE1NvwkxTi80XdAA-lXaRCoNVg8QSDNkrBMA"
dim SR As New IO.StreamReader(WC.OpenRead(redirectURL))
responseText = SR.ReadToEnd()
SR.Close()
FYI : I have stepped throught the debugger, without that how could i post the stack trace in my previous post
and one more thing the same code with same requet URL working in other page. Also please look at the stacktrace in my first post, it is showing some FileIOPermission problem. I am wondering what is related to FIleIOPermission with webclient request or webrequest.
MORE INFO:
-----
The pages actually resides in two seprate virtual directories(In separate webprojects). The location of both pages are as follow, the code specified above is running on both's Page_Load event:
1. Main virtual directory
http://localhost/kg/GeoCodeHelper.aspx <- This page running fine
2. Sub directory of main directory, but itself is virtual directory residing complete new website. This CMS directory is virtual directory having full new website but is inside the main KG directory.
http://localhost/kg/CMS/GeoCodeHelper.aspx <- This page is throwing above discussed error
I just want to know from experts that though I am making the webrequest the stacktrace shows the error has been throwed from fileIOPermission in hierarchy. So can anybody tell me what is related between File IO and web request?
Scott LyslePosted Apr 30, 2008, 4:52 AM