tag:blogger.com,1999:blog-30018142108531945842024-03-01T19:00:40.080+11:00ASP.NET Tutorials and TweaksThis blog contains .NET Tutorials and Tweaks that are required by any ASP.NET Programmer or Web Developer on daily basis in commercial level.
These tutorials are also handy for programmers that are at beginner level.HThttp://www.blogger.com/profile/13378915334043285183noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-3001814210853194584.post-67464414665730034392013-12-02T13:58:00.000+11:002013-12-03T08:49:49.096+11:00<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: center;">
<b>IE 11 compatibility for ASP.NET Framework</b></h2>
<div>
<b><br /></b></div>
<div>
With the release of IE 11 there has been compatibility issues with .NET Framework 4.0 and likewise every developer it has been a nightmare for all the sites that were not catering for this change/upgrade.</div>
<div>
<br /></div>
<div>
<b><u><span style="color: red;">Issue: </span></u></b><br />
Internet Explorer version 11 (IE 11) has thrown many sites either on javascript variables or CSS styling with errors such as "<br />
<div style="text-align: center;">
<span style="color: red;">“The value of the property '' is null or undefined, not a Function object”</span></div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: justify;">
<span style="color: red;"><b><u>Cause</u></b>:</span><br />
Internet Explorer 11 does not recognize .NET Framework properly.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<u><b><span style="color: red;">Resolution:</span></b></u></div>
<div style="text-align: justify;">
This issue can be fixed by adding "App_Browsers" folder into your website or web application project.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
If App_Browsers folder does not exist in your current solution/website/project, then follow these steps:</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
1. Right Click on your project/website name </div>
<div style="text-align: justify;">
2. Go to Add </div>
<div style="text-align: justify;">
3. Go to "Add ASP.NET folder</div>
<div style="text-align: justify;">
4. Select "App_Browsers"</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Otherwise:</div>
<div style="text-align: justify;">
1. Right click on "App_Browsers" folder </div>
<div style="text-align: justify;">
2. Add New Item</div>
<div style="text-align: justify;">
3. Select browser file, name it ie11.browser</div>
<div style="text-align: justify;">
4. Copy the following code(red text) into ie11.browser file</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
CODE TO COPY:</div>
<div style="text-align: justify;">
<i><span style="color: red;"><browsers></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <browser id="IE11" parentID="Mozilla"></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <identification></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <userAgent match="Trident\/7.0; rv:(?'version'(?'major'\d+)(\.(?'minor'\d+)?)(?'letters'\w*))(?'extra'[^)]*)" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <userAgent nonMatch="IEMobile" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> </identification></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capture></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <userAgent match="Trident/(?'layoutVersion'\d+)" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> </capture></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capabilities></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="browser" value="IE" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="layoutEngine" value="Trident" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="layoutEngineVersion" value="${layoutVersion}" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="extra" value="${extra}" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="isColor" value="true" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="letters" value="${letters}" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="majorversion" value="${major}" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="minorversion" value="${minor}" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="screenBitDepth" value="8" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="type" value="IE${major}" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="version" value="${version}" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> </capabilities></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> </browser></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"><br /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <!-- Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11,0) like Gecko --></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <browser id="IE110" parentID="IE11"></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <identification></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="majorversion" match="11" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> </identification></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"><br /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capabilities></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="ecmascriptversion" value="3.0" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="jscriptversion" value="5.6" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="javascript" value="true" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="javascriptversion" value="1.5" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="msdomversion" value="${majorversion}.${minorversion}" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="w3cdomversion" value="1.0" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="ExchangeOmaSupported" value="true" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="activexcontrols" value="true" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="backgroundsounds" value="true" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="cookies" value="true" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="frames" value="true" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="javaapplets" value="true" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="supportsCallback" value="true" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="supportsFileUpload" value="true" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="supportsMultilineTextBoxDisplay" value="true" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="supportsMaintainScrollPositionOnPostback" value="true" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="supportsVCard" value="true" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="supportsXmlHttp" value="true" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="tables" value="true" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="supportsAccessKeyAttribute" value="true" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="tagwriter" value="System.Web.UI.HtmlTextWriter" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> <capability name="vbscript" value="true" /></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> </capabilities></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"> </browser></span></i></div>
<div style="text-align: justify;">
<i><span style="color: red;"></browsers></span></i></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
5. Save the file and build the project(recommended but not mandatory, but on saving the file all your sessions will be disposed)</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
6. Re-test your project.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
I hope this would help many developers and save the tiring time of re-search.<br />
<br />
<h3>
<b><span style="color: red;"><i>Your feedback will be much appreciated. </i></span></b></h3>
</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Cheers</div>
</div>
</div>
HThttp://www.blogger.com/profile/13378915334043285183noreply@blogger.com0tag:blogger.com,1999:blog-3001814210853194584.post-15138945348031417062013-04-22T12:46:00.000+10:002014-02-11T15:58:07.327+11:00Soap Header Authentication for Web Services in ASP.NET<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div style="text-align: left;">
Hi All,</div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
I will be discussing web service authentication in this article, where you can host your web service publically but it can only be accessed by passing pre-assigned username, password and secure parameter. </div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
So speaking simple SOAP web services, following are the steps that will make your publically available web service, a secured web service.</div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
</div>
When you choose to create a new web service(for .NET 2.0/3.0/3.5), you will see the following Service1.asmx code-behind. (Note: I've added "System.Web.Services.Protocols" namespace and "#region" tag in the default code.<br />
<br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRMhtUaTVesAx3pxi-Wv5jDtwjT_Xqip0qbGD5Tgkxr6SEKJ9xYDpFvVw4ItSwGiL_hyWFGMiaCHFwj71eARFfvsdQ0s0qPXjeMuB5xG4WQ3W9i3rbNk4jQsxFwMrFwQpVwVtRdOrT-Pj8/s1600/DefaultWS.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRMhtUaTVesAx3pxi-Wv5jDtwjT_Xqip0qbGD5Tgkxr6SEKJ9xYDpFvVw4ItSwGiL_hyWFGMiaCHFwj71eARFfvsdQ0s0qPXjeMuB5xG4WQ3W9i3rbNk4jQsxFwMrFwQpVwVtRdOrT-Pj8/s640/DefaultWS.png" height="529" width="640" /></a><br />
<div style="text-align: left;">
</div>
<div>
This is an example of default web service code which will let HelloWorld() method to be consumed without any authentication, once this web service is published over the App Server(local IIS or over Internet).</div>
<div>
<br /></div>
<div>
By adding couple of lines of code we can make the existing web service to be secure(i.e.by enforcing username and password via SOAP Header).</div>
<div>
<br /></div>
<div>
So let's pick some username and password for the web service and place it within <appSettings> tag in Web.config file. </div>
<div>
<br /></div>
<div>
<div>
<i><span style="color: red;"><b> <appSettings></b></span></i></div>
<div>
<i><span style="color: red;"><b> <add key="ff_username" value="user1"/></b></span></i></div>
<div>
<i><span style="color: red;"><b> <add key="ff_password" value="User!123"/></b></span></i></div>
<div>
<i><span style="color: red;"><b> </appSettings></b></span></i></div>
</div>
<div>
<br /></div>
<div>
Now to implement this username and password, we need to modify the current web service code as shown in highlighted boxes below:</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgseKKZbytckLhQSj0REqFatqGf-OAltObKdyYjgApbg38uldaqctI_BkYrsMCTuVhkAtoIKdkfMwH8Pl7DsuAabXEu2jPs1dwamJBbyGtzxKXkwq13rVm3FRQc-vzRICxjFiHGiVglhoi2/s1600/securedWS.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgseKKZbytckLhQSj0REqFatqGf-OAltObKdyYjgApbg38uldaqctI_BkYrsMCTuVhkAtoIKdkfMwH8Pl7DsuAabXEu2jPs1dwamJBbyGtzxKXkwq13rVm3FRQc-vzRICxjFiHGiVglhoi2/s640/securedWS.png" height="574" width="640" /></a></div>
<div>
<br /></div>
<div>
Now this web service is secured with customer username and password. After a successful build you can deploy/publish this web service on your IIS(local or Internet).</div>
<div>
<br /></div>
<div>
<span style="color: red;"><b><u>HOW TO TEST IF THE ABOVE WEBSERVICE IS WORKING WITH USERNAME & PASSWORD AUTHENTICATION</u></b></span></div>
<div>
<span style="color: red;"><b><u><br /></u></b></span></div>
<div>
You can create a "Test Project" where you can add the service reference by right clicking on "Web Reference"--> choosing "Add Web Reference" and providing the URL of your currently deployed web service.</div>
<div>
<br /></div>
<div>
Assuming that you have given the web reference name of your web service(under Test Project) as "prod", it should look something as shown below.</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCJotaQlTAv6bCuNyNn48W48agEn0-Gw6-wPadyvAbB_ViJEni2bXiaD49mMHkcBBSLVsIGfuSgdpFvBz1LzeRaO68e5nF_GJb2Y9AwGIhvu9tEWNlM_3-V_EIgP2hKO0_FHe5iUKCDYM4/s1600/testWS.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCJotaQlTAv6bCuNyNn48W48agEn0-Gw6-wPadyvAbB_ViJEni2bXiaD49mMHkcBBSLVsIGfuSgdpFvBz1LzeRaO68e5nF_GJb2Y9AwGIhvu9tEWNlM_3-V_EIgP2hKO0_FHe5iUKCDYM4/s1600/testWS.png" /></a></div>
<div>
<br /></div>
<div>
Now in the code-behind of your "Default.aspx.cs", create the web service instance and consume the HelloWorld() and display it in Label.Text as shown below:</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4A8QxVPj8WN_dY-caLG9zzAkoREUw20uVw8_5tQ7_9iagwzI5v0XTXFrR2NNsYXHLzjGWH5zLJM60vd15t5waK3aWc6drKQMaZnW-BUlPqGTQ7cqoZtJutvrIZuLNLa007QmkkriNNMwr/s1600/testWSSecure.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4A8QxVPj8WN_dY-caLG9zzAkoREUw20uVw8_5tQ7_9iagwzI5v0XTXFrR2NNsYXHLzjGWH5zLJM60vd15t5waK3aWc6drKQMaZnW-BUlPqGTQ7cqoZtJutvrIZuLNLa007QmkkriNNMwr/s640/testWSSecure.png" height="395" width="640" /></a></div>
<div>
<br /></div>
<div>
As stated in commented text, if your web service fails the authentication it will display "Authentication Failed" otherwise it will display "Hello World".</div>
<div>
<br />
<br /></div>
<div>
Cheers :-)</div>
<div>
<br /></div>
</div>
HThttp://www.blogger.com/profile/13378915334043285183noreply@blogger.com53tag:blogger.com,1999:blog-3001814210853194584.post-28398746719300844982013-04-15T16:41:00.002+10:002014-02-11T16:05:28.557+11:00Consume Google Maps geoCode API Web Service in .NET<div dir="ltr" style="text-align: left;" trbidi="on">
Hi,<br />
<br />
In this post I will be talking about geocoding the address and extracting XML node values such as "Google defined address(Formatted_Address)", "Latitude", "Longitude" etc.<br />
<br />
As we all must have searched some address location on <a href="https://maps.google.com/" target="_blank">Google Maps</a> so I'm assuming you all to be aware with the basic look & feel and working of Google Maps.<br />
<br />
Mostly we enter one address at a time on "Google Maps" UI, which in turn, redirects and points the location using markers.<br />
In the scenario where you have to search for specific nodes or node-values i.e. customized search for any associated value for a particular address, it may be tedious and frustrating.<br />
<br />
So lets see how we can use the freely available "Google Maps API" and attain our desired results.<br />
For full documentation on Google API Web Services visit <a href="https://developers.google.com/maps/documentation/webservices/" target="_blank"><b>Google API </b></a><br />
<br />
The web service request is made in the format given below:<br />
<br />
<span style="background-color: #fafafa; color: #007000; font-family: 'Droid Sans Mono', monospace; font-size: 13px; line-height: 1.5;">http://maps.googleapis.com/maps/api/</span><i style="color: #007000; font-family: 'Droid Sans Mono', monospace; font-size: 13px; line-height: 1.5;">service</i><span style="background-color: #fafafa; color: #007000; font-family: 'Droid Sans Mono', monospace; font-size: 13px; line-height: 1.5;">/</span><i style="color: #007000; font-family: 'Droid Sans Mono', monospace; font-size: 13px; line-height: 1.5;">output</i><span style="background-color: #fafafa; color: #007000; font-family: 'Droid Sans Mono', monospace; font-size: 13px; line-height: 1.5;">?</span><i style="color: #007000; font-family: 'Droid Sans Mono', monospace; font-size: 13px; line-height: 1.5;">parameters </i><br />
<br />
Although the same web service can also be access via HTTPS protocol in the format given below:<br />
<span style="background-color: #fafafa; color: #007000; font-family: 'Droid Sans Mono', monospace; font-size: 13px; line-height: 1.5;">https://maps.googleapis.com/maps/api/</span><i style="color: #007000; font-family: 'Droid Sans Mono', monospace; font-size: 13px; line-height: 1.5;">service</i><span style="background-color: #fafafa; color: #007000; font-family: 'Droid Sans Mono', monospace; font-size: 13px; line-height: 1.5;">/</span><i style="color: #007000; font-family: 'Droid Sans Mono', monospace; font-size: 13px; line-height: 1.5;">output</i><span style="background-color: #fafafa; color: #007000; font-family: 'Droid Sans Mono', monospace; font-size: 13px; line-height: 1.5;">?</span><i style="color: #007000; font-family: 'Droid Sans Mono', monospace; font-size: 13px; line-height: 1.5;">parameters</i><br />
<i style="color: #007000; font-family: 'Droid Sans Mono', monospace; font-size: 13px; line-height: 1.5;"><br /></i>
<br />
For the browser to make web service call to Google Maps API, following url string is parsed where address take the parameter value {0}:<br />
<i>http://maps.google.com/maps/api/geocode/xml?address={0}&sensor=false </i><br />
<i><br /></i>
To make it more simpler, I'm using Melbourne, Australia as the parameter value for address field. This will be interpreted by the system in the format:<br />
<b><i>http://maps.google.com/maps/api/geocode/xml?address=Melbourne,Australia&sensor=false</i></b><br />
<b><i><br /></i></b>
To see the results you can directly paste the above url into your browser and see the results<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEY-rVz3GeRKZbY1AFY6oYPckWShHiwNHpAi6IjyCOGXxsKec4xv5yiwwdNV21u9tlJ_nCnD9vDQZcRWiqgfk68zwFGEL6YzEzbeZRrJu7jd0XcnmoukMZOPfh1jp7xWD98BXCNQQlKpPC/s1600/geocode.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="Google API Web Service Call Result" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEY-rVz3GeRKZbY1AFY6oYPckWShHiwNHpAi6IjyCOGXxsKec4xv5yiwwdNV21u9tlJ_nCnD9vDQZcRWiqgfk68zwFGEL6YzEzbeZRrJu7jd0XcnmoukMZOPfh1jp7xWD98BXCNQQlKpPC/s1600/geocode.png" height="400" title="" width="250" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><b>Results for Google API Web Service Call with Address as Melbourne, Australia</b></td></tr>
</tbody></table>
<br />
Now this XML result set gives you all the nodes that can be used, based on your requirements. But it's hard to manually change the address values when geocoding hundreds or thousands of addresses.<br />
<br />
To overcome this scenario I opted for reading all the addresses from a text file in the format using while loop:<br />
<b>uniqueID:address</b><br />
<b>uniqueID:address</b><br />
<b>uniqueID:address</b><br />
<br />
<u><b>Method ReadAddressFromFile on PageLoad or Button Click</b></u><br />
<br />
<br />
private void ReadAddressFromFile()<br />
{<br />
try<br />
{<br />
// Create an instance of StreamReader to read from a file.<br />
// The using statement also closes the StreamReader.<br />
using (StreamReader sr = new StreamReader(@"D:\geocode\Uploads\Address_1.txt"))<br />
{<br />
String line;<br />
string _address = "";<br />
// Read and display lines from the file until the end of<br />
// the file is reached.<br />
while ((line = sr.ReadLine()) != null)<br />
{<br />
_recordCount++;<br />
Session["_recordCount"] = _recordCount;<br />
_merchantID = line.Split(':');<br />
Session["_merchantId"] = _merchantID[0].ToString();<br />
<br />
_address = _address + line+"\n\n";<br />
_address = _address.Replace("\t", " ");<br />
Session["addressFromFile"] = _merchantID[1].ToString();<br />
<b>FindCoordinates();</b><br />
_address = ""; //<br />
}<br />
<br />
}<br />
}<br />
catch (Exception ex)<br />
{<br />
// Let the user know what went wrong.<br />
}<br />
}<br />
<br />
<br />
In the above code snippet, on each line read "FindCoordinates" Method is been called where I'm passing ID and address after delimiting/tokenizing on ':' (If you remember uniqueID:address still :) )<br />
<br />
Now let's see what's happening in FindCoordinates method...<br />
<u><b>Method FindCoordinates()</b></u><br />
<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>private void FindCoordinates()<br />
{<br />
try<br />
{<br />
url = String.Format("http://maps.google.com/maps/api/geocode/xml?address={0}&sensor=false", Session["addressFromFile"].ToString().Replace(" ", ","));<br />
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);<br />
HttpWebResponse response = (HttpWebResponse)request.GetResponse();<br />
Stream outputStream = response.GetResponseStream();<br />
StreamReader reader = new StreamReader(outputStream, Encoding.ASCII);<br />
output = reader.ReadToEnd();<br />
<br />
response.Close();<br />
outputStream.Close();<br />
reader.Close();<br />
<br />
//write to File <br />
<b>deSerializeResponse();</b><br />
}<br />
catch (Exception ex)<br />
{<br />
//Catch execptions here<br />
}<br />
finally<br />
{<br />
//clear any session values<br />
}<br />
}<br />
<br />
<br />
In the above code snippet, web service call is made with address parameter from Session value "addressFromFile" which is assigned in <b><u>ReadAddressFromFile</u> </b>method.<br />
<br />
<br />
What Happens in deSerializeResponse Menthod?<br />
<br />
Here's the snippet:<br />
<br />
<br />
private void deSerializeResponse()<br />
{<br />
string _lat = "";<br />
string _long = "";<br />
string results = "";<br />
string formatted_address = "";<br />
string oldFileName = @"D:\geocode\Uploads\XMLOutput.txt";<br />
string newFileName = @"D:\geocode\Uploads\myXmFile.xml";<br />
File.Delete(oldFileName);<br />
// Write the string to a file.<br />
System.IO.StreamWriter file = new System.IO.StreamWriter(@"D:\geocode\Uploads\XMLOutput.txt");<br />
System.IO.StreamWriter wsResultFile = File.AppendText(@"D:\geocode\Uploads\WebServiceResult.txt");<br />
// Retrieve XML document <br />
<br />
XmlTextReader reader = new XmlTextReader(new StringReader(txtLatitude.Text));<br />
<br />
// Skip non-significant whitespace <br />
reader.WhitespaceHandling = WhitespaceHandling.Significant;<br />
file.WriteLine(txtLatitude.Text);<br />
<br />
file.Close();<br />
File.Delete(newFileName);<br />
File.Move(oldFileName, newFileName);<br />
XmlDocument xdXml = new XmlDocument();<br />
xdXml.Load(@"D:\geocode\Uploads\<b>myXmFile.xml</b>");<br />
//Make a nodelist<br />
XmlNodeList nodes = xdXml.SelectNodes("<b>//GeocodeResponse/result</b>"); //<span style="color: #ffd966;">1</span><br />
foreach (XmlNode node in nodes)<br />
{<br />
formatted_address = node["formatted_address"].InnerText;<br />
}<br />
nodes = xdXml.SelectNodes("<b>//GeocodeResponse/result/geometry/location</b>"); //<span style="color: #ffd966;">2</span><br />
foreach (XmlNode node in nodes)<br />
{<br />
_lat = node["lat"].InnerText;<br />
_long = node["lng"].InnerText;<br />
}<br />
results = Session["_merchantId"].ToString() + " | " + Session["addressFromFile"].ToString().Trim() + " | " + formatted_address + " | " + _lat + " | " + _long; <br />
wsResultFile.WriteLine(results);<br />
wsResultFile.Close();<br />
}<br />
<br />
<i>"There are few files that I've created for myself so don't get confused in number of files been created in the above code snippet ;-) "</i><br />
<br />
<br />
Mainly, you are looking at "myXmFile.xml" from where iterate through each node of GeocodeResponse>>result (refer <span style="color: #ffd966;">1</span> in the code snippet) and further iterate within geometry>>location node(refer <span style="color: #ffd966;">2</span>) to read latitude("lat") and longitude("lng") values.<br />
<br />
<br />
<i><u>Why I used uniqueID?</u></i><br />
Because, all these geocode results will be uploaded into database with these ID mappings.<br />
<br />
The above scenario will be often seen for web apps or mobile apps where you have to list down addresses or locations based on "GPS current location", "Postcode", "region" searches.<br />
<br />
Cheers!</div>
HThttp://www.blogger.com/profile/13378915334043285183noreply@blogger.com1tag:blogger.com,1999:blog-3001814210853194584.post-49355845182428028362012-04-27T17:20:00.002+10:002012-04-29T20:23:58.320+10:00Uploading Large files in asp.net and IIS 7.0 and higher<div dir="ltr" style="text-align: left;" trbidi="on">
Hi,<br />
<div>
<br /></div>
<div>
I'm hoping this would be helping out many of alike programmers facing file upload issue with asp.net, as it took me few different troubleshooting paths to eventually get large files uploading functional for the applications that were working perfectly fine UNTIL I moved these application to IIS 7.0 from IIS 6.0.</div>
<div>
<br /></div>
<div>
Recently I migrated our hosting servers from IIS 6.0 to IIS 7.5 including all the source code and mark-up files(in c#.net). Since that day applications with "FileUpload" functionality started displaying "Page cannot be displayed" message when ever large files were uploaded.</div>
<div>
<br /></div>
<div>
I tried increasing executionTimeOut and maxRequestLength (which would be the first thought in every developer's mind) but it didn't worked. Finally the solution to this issue (asp.net file upload on IIS 7.0 or higher) turned out to be the changed web.config element to cater larger files!!</div>
<div>
<br /></div>
<div>
In <system.webServer> you need add the following line of code and it would definitely work for large uploads:</div>
<div>
<div>
<strong><span style="color: #cccccc;"> <security></span></strong></div>
<div>
<strong><span style="color: #cccccc;"> <requestFiltering></span></strong></div>
<div>
<strong><span style="color: #cccccc;"> <requestLimits maxAllowedContentLength="2294967296" /></span></strong></div>
<div>
<strong><span style="color: #cccccc;"> </requestFiltering></span></strong></div>
<div>
<strong><span style="color: #cccccc;"> </security></span></strong></div>
</div>
<div>
<br /></div>
<div>
<em><u><span style="color: red;">Make sure your session timeout value is high enough to keep the upload happening else your page would expire regardless.</span></u></em></div>
<div>
<br /></div>
<div>
Thank you,</div>
<div>
<br /></div>
</div>HThttp://www.blogger.com/profile/13378915334043285183noreply@blogger.com0