Saturday, October 29, 2011

99X Brouhaha Picture Gallery

Digits in Motion is very excited to be working with 99X on this year's 99X Brouhaha Fan-Driven Photo Gallery. Event attendees can share all their pictures from the night by adding them to http://99xbrouhahapix.com - with easy import integration from Facebook and Flickr, it only takes 3 clicks to share your pictures with others who attended. You can tag costumes, to make it easy to find yourself in others pictures or find costumes you liked.

99X Brouhaha Photo Gallery | Share and Search Pictures From 99X Brouhaha

Wednesday, April 6, 2011

Pull API response using HttpWebRequest in ASP.NET (Yelp Example)

Many ASP.NET APIs will come with classes set up to help you easily pull information (such as Google, Facebook, YouTube, etc), but sometimes, such as in the case of Yelp, you'll need to connect to a URL to pull a JSON object or string.

Here's a quick and simple say to do this:
Public Sub Form_Load() Handles Me.Load
Dim apiURL As String = "http://api.yelp.com/phone_search?phone=6785557743&ywsid=####-########_#######"
Dim uri As New Uri(apiURL)
If (uri.Scheme = uri.UriSchemeHttp) Then
Dim request As HttpWebRequest = HttpWebRequest.Create(uri)
request.Method = WebRequestMethods.Http.Get
Dim response As HttpWebResponse = request.GetResponse()
Dim reader As New StreamReader(response.GetResponseStream())
Dim tmp As String = reader.ReadToEnd()
response.Close()
myLiteral.Text = tmp
End If
End Sub


What we've done here is sent a HttpWebRequest out to ping the apiURL as defined by the first line of my Form_Load sub. In this case, I took a Yelp API url (you'll need to fill in the phone number, yelp api ID), but you can use any url. This particular Yelp one will return a serialized JSON Object that I can then parse out and use the information however I want.

Desired result of this HttpResponse:


After I post my request to Yelp, I can pull their response into a stream and display it to my web page using a literal, in my case, I've used a control named 'myLiteral'.

It's really that easy and fairly simple to adapt to any kind of response you'll get.

Thursday, March 31, 2011

Issues When Migrating to IIS7: Default Documents and Images

I recently migrated all of my company's websites to a new server, upgrading from IIS6 to IIS7 in the process. There were several hurdles we had to jump in making the version change and I thought it may help others to learn from our experiences.

Default Documents can not include Query Strings


IIS7 Default Documents

The Issue


On our older server, we had many domains feeding into the same web application, yet each domain would set certain variables through the query strings of the default document of the site.

For instance, a domain "myExample.com" a default page "DefaultPage.aspx?e=29" would set all the variables necessary for portal #29.

With IIS7, we no longer have this luxury, and must only feed in a single filename, i.e. "DefaultPage.aspx"

Issues for Multiple Websites with the Same Home Directory


One of my first thoughts was, ugh, am I really going to have to create a seperate landing page for EVERY domain linking into the site? As you'll read in the work-around, no. That's not the best way to do it. And as it turns out, it's not even possible. For every Home Directory you route to in IIS7, you have to use the same landing page for all websites pointing to that folder. So, if I have myExampleA.com and myExampleB.com both pointing to c:\inetpub\wwwroot\myExamples\ and I define myExampleA.com's default document to be WelcomeToA.aspx, then myExampleB.com will inherit the same default document. They have to be the same. Another big change for default documents when migrating from IIS6 to IIS7.


The Solution


I've noted several people using URL Rewrites to solve this, but with an application as large as ours, it would take days to test everything to ensure implementing an application wide URL Rewrite wouldn't cause any problems elsewhere.

But, since every domain sets a different set of variables, I was able to find a simple solution.

I feed every domain into the same default document, i.e. RerouterPage.aspx that then looks at the domain of the request, compares it to my database to determine the portal ID (the ?e=##) of the request and then set all the variables accordingly. Afterwards it redirects the user to the correct landing page.

Here's a little sample of what my code looked like for the RerouterPage.aspx
Public Sub Form_Load() Handles Me.Load

If Session("portal") Is Nothing Then

If Request("e") = "" Then

Session("portal") = PullPortalBasedOnDomain()

Else

If IsNumeric(Request("e")) Then

Session("portal") = New Portal(Request("e"))

Else

Response.Redirect("~/NoPortal.aspx")

End If

End If

End If

If CType(Session("portal"), Portal).PortalID = 0 Then

Response.Redirect("~/NoPortal.aspx")

End If



Response.Redirect("~/" & CType(Session("portal"), Portal).LandingPage)

End Sub


Private Function PullPortalBasedOnDomain() As Portal

Dim thisDomain As String = "http://" & Request.ServerVariables("SERVER_NAME").ToString

thisDomain = thisDomain.Replace("www.", "")

Return Portal.GetPortalBasedOnDomain(thisDomain)

End Function



IIS7 Blocks Images in Bin Folders


IIS7 Blocks Images in Bin Folders

The Issue


I got into kind of a stupid habit left over from when I used to develop in PHP, but when I make an images folder, I usually divide my images up into several different subfolders related to their purpose and for all general images, I just toss them into a subfolder named "bin". You can probably guess where this is going. IIS7 blocks view access to all folders in your solution named bin. Unfortunately, the images/bin/ folder is referenced throughout the entire site and would be a monsterous task to go through and replace.

The Solution


Luckily, through some research I found this work around that seems to work great:
    </system.webServer>
<location path="images/bin">
<system.webServer>
<security>
<requestFiltering>
<hiddenSegments>
<remove segment="bin" />
</hiddenSegments>
</requestFiltering>
</security>
</system.webServer>
</location>

Now the bin subfolder within the images folder has view access.

Tuesday, February 1, 2011

How to sort a YouTube Query with the .NET API SDK

Having trouble sorting the .NET YouTube API video feed?

Countless sites will tell you than in order to sort your videos by the date they were published, all you need to do is set the query.OrderBy property or in some instances the query.setOrderBy property to Google.GData.YouTube.YouTubeQuery.OrderBy.Published.

While working with Intellisense, I noticed that no such values are provided by the OrderBy method. I attempted just using a string query.OrderBy = "Published" but got an error "". Likewise, I thought maybe it's a numerical Enum type and attempted query.OrderBy = 1, but still no luck.

Finally after doing a bit of trial and error, I got it to work with the string "published" (all lowercase).

query.OrderBy = "published"

You can order your videos by a couple different fields, but the string must match these options case sensitvely:

relevance
published
rating
viewCount
Notice: viewCount has an uppercase C

Tuesday, January 25, 2011

Getting your .NET 4.0 site to work with II6

Having trouble getting your ASP.NET 4.0 site to work while using IIS 6?

I recently encountered the same problem, but was able to get it working by enabling the dll for the .NET 4 ASP.NET ISAPI extension.

Johan Driessen has put together a great tutorial on how to do this:
http://johan.driessen.se/archive/2010/04/13/getting-an-asp.net-4-application-to-work-on-iis6.aspx

Thursday, January 20, 2011

Reference Removed Build Visual Studio 2010

Having trouble with a reference you imported when you try to build or debug an application with Visual Studio 2010?

I noticed an issue with VS2010 when I was creating a simple VB.NET console application using Google's GData Client API. I began by adding the reference to a .dll file and then adding a "Imports Google.GData.Client" to the top of my code. All pretty standard right?

I was then able to write out the code for my application using this API; everything seemed to be working fine. Intellisense picked up the classes and all. Then I tried to debug and everything fell apart.

Suddenly it was if I had never added the reference to my class. I was getting Type not defined errors and namespace issues with my imports statement. I checked my references and found my expected .dlls, but went ahead and re-added them anyways. All my errors cleared out and everything again looked fine. I tried to build and debug again and kept hitting the same issue.

After a long time, I finally found a solution!
Go to your application's properties, click on the Compile tab and set the "Target framework (all configurations):" dropdown from ".NET Framework 4 Client Profile" to ".NET Framework 4"


Click OK and save. Your applications will probably shut down all windows, but now you should be able to debug and build your application successfully (assuming you have no other errors). At least the reference issue will be solved.

Pay no attention to the man behind the curtain!

Example of a standard link created with brackets:
Web Design Blog

Example of same link created with ampersand encoding of brackets so the source code will show up on an html page:
<a href="http://www.robfine.com/RobFineWebDesign.aspx">Web Design Blog</a>

Render ASP Control To HTML String

Every now and then, you may come across the need to convert an ASP.NET control to html. For instance, if you were drafting an HTML email with your site, you may create the content of the email with .NET controls, then convert it to html to place into the body of the message.

I recently ran across the need to convert an asp hyperlink control to its html equivalent as part of a function used in creating a GridView.

My gridview contained an Eval and Function:
<div style="font-style: italic; font-size: 11px;">
Answered by <%#ShowName(Eval("faq_author"))%>
</div>


So, I attempted to use the function ShowName plant a control itself in the gridview:
Public Function ShowName(ByVal thisID As Integer) As HyperLink
Dim thisAuthor As New FaqAuthor(thisID)
Dim thisLink As New HyperLink()
thisLink.Text = thisAuthor.Name
thisLink.NavigateUrl = thisAuthor.ProfileURL
Return thisLink
End Function


Unfortunately, this doesn't work out like you'd hope:


But, there's an easily solution to change that System.Web.UI.WebControls.HyperLink into an actual html hyperlink. Using the IO.StringWriter class and HtmlTextWriter class, we can execute the .RenderControl function that can be found in nearly .NET control that renders into an HTML element.

My final ShowName function should look like this:
Public Function ShowName(ByVal thisID As Integer) As String
Dim thisAuthor As New FaqAuthor(thisID)
Dim thisLink As New HyperLink()
thisLink.Text = thisAuthor.Name
thisLink.NavigateUrl = thisAuthor.ProfileURL
Dim myStringWriter As New IO.StringWriter()
Dim myHtmlWriter As New HtmlTextWriter(myStringWriter)
thisLink.RenderControl(myHtmlWriter)
Return myStringWriter.ToString
End Function


And it works perfectly.
My gridview now shows hyperlink text that gives my users' name and links to their profiles.

Thursday, January 13, 2011

Given Path Not Supported on Uploads with PostedFile.FileName

Have you intermittently been experiencing issues with uploads on your ASP.NET site?
Seeing errors thrown like "The given path is not supported"?

I recently stumbled across this issue with a couple of pages. I was able to dig down and fix all of my code to handle uploads again.

It looks like the code I was formerly using to save files to my web server is no longer functioning the way it used to. Previously, I saved files something to the style of:
myFileUpload.SaveAs("C:\uploads\" & myFileUpload.PostedFile.FileName)

When I started exploring the error, I discovered that the file path being generated was:
C:\uploads\C:\Users\robfine\Desktop\myFileToUpload.txt

It seems that the function .PostedFile.FileName no longer returns just the name of the file being uploaded, but rather the entire path the file was located at on the uploader's computer.

It's an easy solution to the issue; all you need to do is use the IO.FileInfo class to extract the name of the file:
Dim myFileName as String = New IO.FileInfo(myFileUpload.PostedFile.FileName).Name
myFileUpload.SaveAs("C:\uploads\" & myFileName)


I've done a little of research and it looks like this may be linked to the browser the end user is using. Some version of IE7 and a couple other browsers throw the entire path of the file out there, while other browsers may only give the filename.

Since you never know what browser your user will be using, it's best to cast the .PostedFile.FileName result into the FileInfo class just to be on the safe side.

Thursday, January 6, 2011

Resolving Facebook.Web assembly error in web.config

I've recently been doing a lot of work with the Facebook SDK Toolkit and found myself with an issue when I uploaded a parent site up to my GoDaddy account.

I have a domain with several folders that host other sites, configured as application roots, but when I uploaded my facebook integrated site to the parent domain, each of the folder sites began experiencing server errors despite being marked as an application root: Could not load file or assembly 'Facebook.Web' or one of its dependencies. The system cannot find the file specified.

I did some research and came up bare, but I was able to figure out the issue myself. I track the bug down to a line in my web.config file:
<httpHandlers>
<add verb="*"
path="facebookredirect.axd"
type="Facebook.Web.FacebookAppRedirectHttpHandler, Facebook.Web" />
</httpHandlers>

This line came from the samples provided with the toolkit, but it appears to be unnecessary for my site's needs, so I just took it out. Everything seems to be working fine now.

Wednesday, January 5, 2011

How to Block Facebook Event Invites from Certain Users

Are you getting spammed by club promoters, bands and other Facebook accounts? I often get several facebook event invitations a day, most of which I have no interest attending. I'd say 90% of those invites all come from about 10% of my friends on Facebook. In the past, I've gone as far as defriending someone to save my inbox from the constant bombardment of their requests, but I finally decided to dig through Facebook's settings to find a way to block any particular user from sending me an invitation to their facebook event.


It's actually pretty easy, you just have to know where to click...

Step 1. In the upper right hand corner of Facebook, click on Account, then click Privacy Settings.



Step 2. At the bottom of the Privacy Settings, click Block Lists.




Step 3. Scroll down to find Block event invites. Fill in the names of users you want to block from sending you Facebook event invitations.



Likewise, on this same page, you can block users from sending you app invites or block users altogether if you don't want them to find you on Facebook.

Monday, January 3, 2011

Resolving Body OnLoad Error BC30456 when runat="Server"

Having trouble loading a javascript function with your body onload call with ASP.NET? If you're getting the Compiler Error Message: BC30456: 'myFunction' is not a member of 'ASP.myMaster', then chances are you've probably set your body to runat="server".


Luckily, there is a way to keep your body running at the server level and a javascript function to the onload method.

First, remove the onload attribute from your body tag:
<body runat="server" id="masterbody">

Now, in the code behind your page or in my case, the master page, add the following code:
masterbody.Attributes.Add("onload", "javascript:myFunction();")