Friday, October 22, 2010

Bing Maps - Setting the size

I have worked with Bing Maps on a few projects now, but had an issue today that took way too long to figure out. I was trying to set the map display size. According to the documentation I should be able to set a div tag to the dimensions I desire and the map will fill the space when it is loaded. I that but I was getting the default (600x400px). Here's the markup I was using:


<div id="map"></div>

div#map
{
position: relative;
width: 100%;
height: 100%;
}


When I examined the markup and style with firebug, I could see Bing Maps was inserting inline styling which caused my styles to not apply due to specificity.

How was it fixed?
After some digging I found this article:
http://msdn.microsoft.com/en-us/library/bb412551.aspx

Which clued me to the fact that I needed to apply a class style and not a element style. Here is the code that fixed it:


<div id="map" class="mapClass"></div>

div#map.mapClass
{
position: relative;
width: 100%;
height: 100%;
}


Thanks Microsoft!

Tuesday, July 27, 2010

Web User Control: Cannot create an object of type 'System.Int32' from its string representation

I had an interesting bug today. I have been creating web user controls based on the structure of database table fields. When I dropped the web user control on to a web form and tried to access its properties from the codebehind, I was getting no intellisense. I then looked at the designer.aspx.cs and notice the web user control was not registering.

After some digging I found an article that seemed to describe my issue that allowed me to narrow down the problem. I followed the "Simple Tip" of deleting the designer.ascx.cs and then regenerating it and found that it was failing because I was using a public property called "Id". Visual Studio 2008 IDE complains about this, and rightfully so. In hindsight I can see why I shouldn't use a reserved name like "Id" for custom a property.

I changed the property name and all references, and I was back in business. It would have been nice to have a better error message to narrow this down quickly, but I'm grateful to have found the issue quickly.

Monday, June 21, 2010

Classic ASP Login failed for user 'NT AUTHORITY\IUSR'

Most often I build asp .net applications and connect to a local development database using windows authentication. I tried to do the same thing (connect using windows authentication) with a classic asp application I'm working on converting to .net, and got this error:
Login failed for user 'NT AUTHORITY\IUSR'

To remedy the issue I did the following:
1. Open Microsoft SQL Server Management Studio
2. On Registered Servers expand nodes to find database server
3. Right-click on database server > Object Explorer
4. Expand 'Security' node
5. Right-click on 'Logins' > 'New Logins...'
6. Login name: 'NT AUTHORITY\IUSR'
7. Click 'OK'
8. Expand 'Databases' node > 'Your_DB_Name' node > Security
9. Right-click 'Users' > 'New user..."
10. User name: 'Whatever_you_want'
11. Login name: NT AUTHORITY\IUSR
12. In the 'Database role membership', check 'db_datareader' and 'db_datawriter'
13. Click 'OK'

That was it - the classic application was able to connect.

I could have created a new user and connected using SQL Server Authentication mode (I actually tried this first, but then realized the server security settings were set to 'Windows Authentication mode' not 'SQL Server and Windows Authentication mode'), but this allowed me to keep my current server security setting of 'Windows Authentication mode' and keep my connection strings consistent between my classic asp and asp .net applications.

IIS 7 and Classic ASP

Since Classic ASP is over a decade old, Microsoft seems to want to forget it ever existed by making it difficult to deploy classic asp apps. I was reminded of this again in a recent project where I am converting an existing classic asp application to a .net app.

I first wanted to set up the classic asp application on my own (windows 7 64bit) machine so I could dissect it and use some of the existing logic. After adding a new application in IIS and trying to browse to the default page, I was getting a 404 error. After googling a bit, I discovered that there must be some special configuration for classic asp apps... and then I found a link that explained that Classic ASP Not Installed by Default on IIS 7.0. That was nice of them - first issue solved.

Second issue: I was then getting this vague error:
An error occurred on the server when processing the URL. Please contact the system administrator.

Thanks! I am the administrator :(

After some digging, I found out that error messages are not sent to the browser by default for asp pages in IIS7 in case sensitive information is displayed. I followed the instructions and now I can see the errors.

Now I can get to work on the conversion.