July 2008 - Posts
There are few things to know , when getting photos from your stream , adding comments and overall doing adding and deletion of your photos. As with flickr you can take a look at this url => http://www.flickr.com/services/api/auth.spec.html for authentication spec to learn more. But with Athena (formerly known as LINQ.Flickr) it's pretty easy to get things going. Last week, I made an update to the FlickrXplorer (The MVC starter project you don't want to miss :-)) project that now enables you to add comments for photos. There is a one click login that will take you to flickr, ask you once for the permission to grant the app for data access and finally will take you back to the place from where you were left off.
Now, concept with MVC app is to call a controller url , and finally point flickr to a second controller url that will bring the user to last page, if everything works fine. This whole thing is done by Athena on behalf without a single line of code on client app.
To start off , lets create a context class.
FlickrContext context = new FlickrContext();
Authentication done in two ways, first one is the auto authentication.
var query = from photo in context.Photos
where photo.SearchText == "Home" && photo.ViewMode == ViewMode.Owner
This query tries to search in my photo stream with word "Home", where the owner is the caller himself. This will automatically take me to the flickr authentication page. However, this is good for desktop based application, where it will fire up the browser , let me authenticate and on closing, it will continue from next line of code. This will also work for web apps, but in case if we need to do something else on successful return, we need a manual way for sure.
Lets say, I call /Photo/Security/Auth url which runs the above line in the controller class that will eventually fire the authentication process. Here to note that once the authentication process is complete all the successive calls will return Authentication token class, which we can use for showing user status or like "Welcome XYZ...".
AuthToken token = context.Authenticate();
if (token != null)
People people = (from p in context.Peoples
where p.NsId == token.UserId
// do the rest.
Finally, if we are on a public computer, we surely don't want to leave without logging off. So, there should be a manual call for that as well.
And, it says all. Technically, Athena stores a token in the App Directory for desktop application with the given path in config for FlickrSettings. In web application, it stores the token in user's browser cookie with 30 days of lifeline for current site which of course goes out as soon as you logout. Token is used by flickr for validating authenticated calls and also by the API to make useful decisions in minimizing service calls.
Hope that gives some light on those who likes to give authenticated features to their personal photo app without much of hair loss.
Again, check things out : www.codeplex.com/linqflickr.
| || |
If you listen to podcast, you will find that Internet is full of it. I do enjoy listening how people talk about things in podcast. I generally listen to hanselminutes , dotnetrocks (Carl Franklin) and few obscure ones. All the episodes of hanselminutes are available in Itunes. Generally I download the latest episode sync into my ipod touch then as my wife busy cooking, I put in the phones in my ear and try to give out some hand, though I remember only to comment and watch but often help preparing salads :-). So, last February before coming from Kuala Lumpur , I bought an IPod touch. Me and my wife both enjoy listening to it, I watched all the Mix 08 videos on it, I do use it to update my twitter status when I am at a coffee shop using the WIFI. Finally, browsing Internet with it a real fun, usually with the tap and zoom feature.
Anyway, its nice to listen to podcasts and talk shows which has become a part of daily lives. Starting from nowhere it is now a source for good knowledge. As recently, I have come to know a cool xaml tool named Kaxaml and Git source control from Linus Torvalds himself. Also, it is nice hear from dotnetrocks about how Phill Hack get into Microsoft or the great Scott Guthrie wrote MVC framework while flying on an airplane.
While I have busy time at work through out the day. I do enjoy listening to all these and more , when I need a thoughtful relax and looking out to ideas for implementing or enhancing my own personal projects.
Now coming back to Ipod, its really a cool device starting from browsing while you are at starbucks , listening to music or watching TV shows when you are on the go. But, one thing for sure it has Itunes bundled with it, so beware of your wallet. One good thing about Zune (Yes the only Zune) that you can sync contents wirelessly and sometimes listen to FM radio , that this great device is not able to provide yet. Also, to be honest I didn't like costly money oriented (or object oriented you say) upgrades that apple offers, it really gives me pain. Yes, this is good device but the dark tails with it goes directly to your wallet. It could have been a more popular device if there were some generosity shown by apple for its content management, DRM rules and pricing. But still with BOSE accessories (sound-dock) , its a fun device you don't want to miss :-).
That's it that came to my mind for now. Also, I want to draw the finish line before the post becomes a soap opera :-) . As it sounds it is a non-technical post , here I haven't talked about LINQ, using LinqExtender toolkit, MVC or anything like it. But do throw me your opinion.
When you are planning to host your asp.net MVC application under IIS7 integrated mode environment. There are few easy tweaks that can make your application or starter kit work right out of the box but also can save a lot of your time finding things out.
You might see a Http 404 page if default document is not configured properly. One way of getting this around by using the following in global.asax during the App_BeginRequest
if (Context.Request.FilePath == "/") Context.RewritePath("Default.aspx");
But rater doing code changes, another easy way of achieving it by adding the following snippet in your web.config
<add value="Default.aspx" />
Relative urls like one that is shown below
<img alt="Flickr Logo" src="/Views/Shared/images/flickr_logo.gif"" />
This will result in invalid output when the app is hosted under IIS7 and if it is hosted under a virtual directory for example, http://localhost/flickrweb. It will produce url http://localhost/Views/Shared/images/flickr_logo.gif rather the original http://localhost/ flickrweb/Views/Shared/images/flickr_logo.gif. To overcome this we would need to use Page.ResolveClientUrl which makes the above snippet look like
<img alt="Flickr Logo"
src="<%= Page.ResolveClientUrl("~/Views/Shared/images/flickr_logo.gif") %>"/>
Now, while hosting our MVC app to a shared hosting server whether or not they provide us a wwwlogs folder, we can easily write down a custom HttpLog module for IIS7 integrated mode (blessing of integrated pipeline). On the Init method of the HttpModule we can add the following event mapping under which we can write our custom logging logic.
context.LogRequest +=new EventHandler(context_LogRequest);
For, each http request this will be fired for IIS7 integrated mode and we need to add the mapping for it in the following way.
<add name="<ModuleName>" preCondition="integratedMode"
We might be using CSS handlers that will be compressing the contents and combine cross browser CSS intelligently, like one I have posted few months back
Make sure you have added the mapping for this as well properly under system.webserver node for integrated mode
<add name="<handlerName>" path="<path>.axd" verb="*"
requireAccess="Script" preCondition="integratedMode" />
And of course add it with Page.ResolveClient url to make it an absolute work.
href="<%= Page.ResolveClientUrl("~/CSSHander.axd") %>" type="text/css" />
Now, hosting extension less web app is all beauty but how if someone tries to overload your server by manually hitting /Views/Controller/SomePage.aspx. We can make sure of it that no .aspx file is ever processed by manual hits, by putting an extra web.config file under /Views folder of you ASP.NET MVC application and adding this tiny line inside it
<add name="InvalidAspxHandler" path="*.aspx" verb="*" preCondition="integratedMode"
type="System.Web.HttpNotFoundHandler, System.Web, Version=184.108.40.206, Culture=neutral
Now, all the config changes I have shown here are to be added under system.webserver node to work with IIS7 integrated mode. The typical webserver node for IIS7 integrated mode looks like
<modules runAllManagedModulesForAllRequests="true" />