Sunday, December 04, 2011

WorkItem only view in TFS 2010 Web Access

Here is an excellent how-to. It covers the very simple scenario as well as more complex approach (in case you need to deal with multiple customers and need more granual settings).
However, there's one glitch that is not mentioned there. TFS has a nasty habit of not picking up domain changes right-away. So if you just created the user & group in your domain, set everything up according to the how-to, you may end up with an error:

Access Denied: {your user} needs the following permission(s) to perform this action: View instance-level information

There's a thread describing the issue. In essence you have a choice of:

  • wait for a bit (30 minutes or so) and TFS will pick it up eventually
  • restart the TFS server
  • instead of using group, use user credentials directly (probably not the best option though)

Saturday, December 03, 2011

Adding Facebook comments to blog

I've decided to try and utilize Facebook Comments Plugin for my travel blog application (ASP.Net). At first glance it seemed like a job for 5 minutes, however it proved to be quite a tricky experience. I had following requirements:

  • need to be able to display multiple comments sections per page (since I have 10 blog-posts on each page and each post needs to have its own comments) that need to be distinguishable by querystring parameters
  • need to have a way of calculating how many comments there are for each post
  • would love to have a way of being able to get latest X comments across all the whole site (i.e. irregardless which blog-post they belong to)


To get started, follow this tutorial (post #11). In essence, you need to set up Facebook Application using following steps:
1. Go to: http://www.facebook.com/developers
2. Click on the + Set Up New App button (at the top right of the page)
3. Type your App Name (example: Mysite-Name Comments) > select Agree > click on Create App
4. Go to the Web Site tab (on the left tabs-list)
5. Enter your site url with an ending slash in Site URL, (for example: http://example.com/)
Enter your site domain without http://www. in Site Domain, (for example: example.com)
and click on Save Changes
6. You will see your Application ID number (above your app API Key & App Secret)
7. It will take between 2 to 20 minutes until it will be ready to use with.

Use this page to see the list of your applications.

Now that you have you aplication set up and you have the application ID, it's time to set up the security settings.  Comments left on for your application can be moderated here - and here using the Settings link you can also adjust the security settings.

Final step is to generate the required code for your page. Use the Comments Tool for that. The top part with generated script is NOT COMPLETE! You do need to register the Javascript SDK - I recommend using the script on that page instead of the one from comment tool (in step 1). Step 2 gives you the DIV element which contains the comments box itself - works like a charm and yes, you can use href with different querystrings.

There are couple of new features that you can read about in this blog post.

You are very close to being done, however there are couple more settings that you should add to your page's header tag. Details are described n the Open Graph Protocol documentation in the Getting Started section. Finally you should add following tag:
meta property="fb:app_id" content="YOUR-APP-ID" 
That will ensure that your moderators will be able to do in-place moderating (i.e. the plugin shows them the "moderate" option)
Use Facebook Debugger to see what settings your page uses and if there's anything that needs your attention.


Monday, July 04, 2011

Getting Could not load file or assembly App_Web for SVC

I have couple of SVC services within an ASP.Net 4.0 website. All works fine with some hiccups (see my previous posts about issues with naming, etc.), but then I started getting errors again when accessing them (500 internal server error). So I investigated what's happening and found out that services are not working and returning:

asp.net svc could not load assembly App_Web...


What the heck? All worked fine and all I did was to add some assembly references to web.config. Turns out that compilation tag may cause this issue - and solution is:

set the "batch" attribute of the "compilation" tag in web.config to "false.

Sunday, June 12, 2011

Getting 400 Bad Data when using svc for AJAX calls

You may run into problems when using WCF service for AJAX calls. I've described how to use it in this post. Turns out, there's one small thing in configuration, that can cause all sorts of problems.
I've named the service "MyService.svc". Registered everything, configured in web.config, but I was still getting errors during load - essentially the ".../MyService.svc/js" (or ".../jsdebug" in debug mode) was returning 400 Bad Data error.
I've finally pinned the problem to web.config setting - the name attribute of the service has to match the class name.
So this is wrong:
<service name="aaaMyService">
...

And this is correct:
<service name="MyService">

Saturday, April 16, 2011

Ajax SVC getting 404 error when using https

We're using AJAX WCF service for javascript calls.
All worked well while we were running under http, but when we went to production and switched to https, all of a sudden service wasn't workin. Following was happening:

http://mytest.com/test.svc/js - worked fine
https://mytest.com/test.svc - worked fine
https://mytest.com/test.svc/js - 404 error

Turned out we were missing binding configuration for https. This blogpost describes how to fix it (i'm attaching the XML fragment just in case the blog goes missing...)

<system.serviceModel>
<behaviors>    
 <endpointBehaviors>
  <behavior name="TestServiceAspNetAjaxBehavior">
   <enableWebScript />
  </behavior>
 </endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
 <service name="TestService">
  <endpoint address="" behaviorConfiguration="TestServiceAspNetAjaxBehavior"
   binding="webHttpBinding" bindingConfiguration="webBinding" contract="TestService" />
 </service>
</services>
 <bindings>
   <webHttpBinding>
     <binding name="webBinding">
       <security mode="Transport">
       </security>
     </binding>
   </webHttpBinding>
 </bindings>
</system.serviceModel>

Tuesday, March 15, 2011

Calling OperationContract in SVC using JavaScript

I was attempting to use WebMethod in a masterpage. Since .Net doesn't support static inheritance, I was out-of-luck. The obvious alternative was to use web-service to do the job. Since I was using .net 4.0, I was hoping to utilize the SVC and not ASMX.

Here's how you can make it work:

1) add "myservice1.svc" using the "Add New Item" -> "AJAX-enabled WCF-Service" menu. Notice that it adds section to your web.config and also "myservice1.cs" into your App_Code.

2) create your method in the "App_Code/myservice1.cs" (sample method below). Warning! If you're using Web Site project as me, don't put anything in the ServiceContract's Namespace!

[OperationContract]
public void SampleMethod1(int param1)
{
// your code here
}

3) Next step is to register this service in your ScriptManager (in my case, I have it on my master page):

<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/myservice1.svc" />
</Services>
</asp:ScriptManager>


4) Finally JavaScript that will call the method:

myservice1.SampleMethod1(2);

It's really that simple - the ScriptManager makes the "myservice1" available and you just call the methods. Again, please note that there's no namespace.

ReportViewer 9 issues

I was stuck with ReportViewer version 9 for one of the projects and I had to resolve 2 major issues.

First issue was the incorrect rendering of the toolbar in Chrome and Safari browsers. At last I found a piece of JS which fixes that (it uses JQuery):

// fix reportviewer toolbar in Chrome / Safari
if ($.browser.safari)
{
$("#<%=rvw1.ClientID %> table").each(function (i, item)
{
$(item).css('display', 'inline-block');
});
}


Second issue was related to apparently well known problem in IE, where the control would render double vertical scrollbars in the report body. Again, I found some JS script fragments that helped me to solve the issue:

// fix the report body size to prevent double-scrollbars in IE
window.onload = function ()
{
var viewer = document.getElementById("<%=rvw1.ClientID %>");
var frame = document.getElementById("ReportFrame<%=rvw1.ClientID %>");
if (frame != null && viewer != null)
{
var reportDiv = eval("ReportFrame<%=rvw1.ClientID %>").document.getElementById("report").contentDocument.getElementById("oReportDiv");
reportDiv.style.height = viewer.style.height;
}
}


Sunday, March 13, 2011

Increasing size of VHD

It happened to me more than once that I've started VPC and only when almost done installing and cofiguring it, I found out that the initial size of the VHD is simply not enough. Well, there's a way to fix that!
You need VhdResizer tool to create a larger copy of the "small" disk. Then you attach that copy to the existing VPC as 2nd drive and extend the volume once booted up.

Monday, February 14, 2011

Migrating project from one TFS to another

As I wrote in couple of my previous posts, we've migrated from TFS 2008 to 2010. This mean new install and btw also new server name.

To make thing interesting, we had to continue work on the code-base in the mean time (un offline mode) and now how to connect it back to the new server?

First - lets sort out workspaces. Get TFS Sidekicks - free, yet priceless tool. Get connected to the new server. Now, in the Workspaces sidekick window, clear out "Owner" and "Computer" fields in the search criteria and hit "Search". This will give you list of all the workspaces that are registered on the server. In my case, I just deleted the ones associated with the TFS2008 instance (as it didn't exist anymore). This "freed-up" the existing folders and I could use them for binding to new TFS2010.

Now you have to remove the workspace entries from local machine. Use the "TF" command tool. For example, executing following statement in the VS's command prompt will show workspaces defined on the computer:

tf workspaces

And this will delete all of them (or you can delete them individualy by name):

tf workspaces /remove:*

Now, you can get latest version of the code from the new TFS version, go offline, ovewrite updated files, go online again and voila!

Setting up security for TFS 2010 in small team

After successfully migrating from TFS 2008 to 2010 (see my previous post), I've faced the challenge of having to set up security. We're very small team of developers, so I was looking for the least-laborious way. So here it is:

1) Create domain users (i'll work with Dev1, Dev2, etc.). Create domain group "Company Developers" and put all the Dev1-n users in it.

2) In TFS Administration Console select "Application Tier".
a) Click "Group Membership". Then "New" to create new group - I named it "Developers". Then click "Properties", select "Windows User or Group", click "Add..." and enter the "Company Developers" domain group & close.

b)Back to "Application Tier". Now click "Administer Security", select the newly created "Developers" and in the list below check last 2 items - "Use full Web Access features" and "View instance-level information".

This step ensures that users from the Company Developers group can connect to the TFS server and see the list of collections.

3) Now one level down, still in TFS Admin Console, select "Team Project Collections" on left. In the detail select the "DefaultCollection" (or whatever collection you created).

a) Click "Group Membership" again and again create "Developers" TFS group (you actually may want to create multiple groups at this level, depending on your requirements). Then click "Properties..." and add either "Company Developers" domain group or individual Dev1, etc... if you work with multiple groups.

b) Click "Administer Security" and on the list below select whatever rights you want to assign (I recommend checking out how the TFS default groups are set to get an idea).

Ok, at this point, we've actually given rights to the users to access the "DefaultCollection". Still can't see any projects, but we're getting close.

4) Now open Visual Studio and in "Team Explorer" connect to the server (if you don't have that on the server, install Team Explorer from the TFS dvd). Once connected (providing you're logged in as administrator), you'll see all the projects in collection. Unfortunately, you DO HAVE TO set rights individually for each project.
So, select project, right-click and "Team Project Settings" -> "Security". There add TFS group "Developers" and set the rights below. If you created multiple groups in 3a, this is where you can use them, to distinguish who has access to what.

That's it. It's very basic, but this way you don't open your TFS too much and still have the flexibility to start being more granual in future should you require so.

Thursday, February 10, 2011

Hyper-V Server Installation

Configuring Win7 client to work with HyperV Remote Management is nicely described here.

I ran into issues where in Server Manager I couldn't connect to "Disk Management". The trick is to enable "Remote Volume Management" rules on the HyperV server's firewall (you can do it through the Server Management from remote machine). More info is here.

Next step is to create PCD virtual machine - nice short how-to is here (unfortunately only in czech).

Trouble with network adapters in VH - help is here.

Sunday, January 30, 2011

Refresh UpdatePanel using JavaScript

In case you'd like to refresh the content of UpdatePanel by javascript (e.g. after PageMethod call, etc.), use following syntax:

__doPostBack('<%=UpdatePanel1.ClientID %>', '');

Notice, that you have to use the ClientID of the control!

Thursday, January 27, 2011

TFS 2008 to 2010 migration

I'll be migrating my TFS 2008 server (32bit) to TFS2010 (64bit) soon. I'll have to completely reinstall the machine, so this is my reading so far:


Monday, January 17, 2011

Hidden workspaces in TFS

I've ran into an issue where I had to switch user under which i was connecting to TFS. Somehow workspace from my previous account was still present in the system and checking out solution to the same folder under the new workspace ended up with errors.
There's a tool called Team Foundation Sidekicks which can help to resolve this situation. You can view all workspaces, modify them, etc... Awesome tool, free one too!

Thursday, January 13, 2011

ASP.Net Web Service Reference error

I've encountered interesting error when dealing with web-services in Web Site (ASP.Net 4.0).
Scenario:
MyWeb - ASP.Net 4.0 web site project
MyService - ASP.Net WCF service
MyCode.dll - library share user by both, MyWeb and MyService.

Now, the issue is when you change MyCode, recompile MyService and do "Update Service Reference" in the MyWeb. What I found, that I start getting compilation errors saying that the client class from the MyService reference is not known (as if the reference was missing).

Cause: The MyWeb project was referencing the MyCode library not as a project, but rather as DLL reference.

Solution: Quite obvious - either use project reference or update the DLL used by the web-site.

This behavior is to be expected, however if you don't realize that you're not using same DLL version from both MyService and MyWeb, it can be quite confusing.