Thursday, August 28, 2008





The request failed with HTTP status 404: Not Found.





I was stuck on this issue for a week till I eventually found the solution and it was in bits and peaces all over the net. But I thought someone might benefit from getting the solution as a whole. Again I haven’t spent enough time to understand the solution but it worked and for now I have to be satisfied with that.







My hosting provider has reporting services installed on a separate machine to the actual website so this should work for most hosting setups. I wanted to embed the reports in my webpage using report viewer. The trick was trying to pass authentication information from my website to the reporting services.








To do this you need to create a ReportServerConnection class and register it in your web.config, along with this you need to add application key/value pairs to pass your report server credentials.






Web Config






Add the following code to a blank page and run then run the code to get the PublicKeyToken






Response.Write("
" +typeof(SportsDB.BLL.SimpleReportServerConnection).AssemblyQualifiedName);





Add the following in your webconfig. It goes under the assemblies tag.




<buildProviders>

<add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx" />

buildProviders>





<add key="MyReportServerUrl" value="https://XXXX"/>

<add key="MyReportViewerUser" value="XXX"/>

<add key="MyReportViewerPassword" value="XXX"/>

<add key="MyReportViewerDomain" value="XXX"/>





As for the code here is the full class – (Don’t you just luv to cut and paste!!)





using System;

using System.Collections.Generic;

using System.Data;

using System.Configuration;

using System.Net;

using System.Security.Principal;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using Microsoft.Reporting.WebForms;





namespace XXXX

{

public interface IReportServerConnection2 : IReportServerConnection, IReportServerCredentials { }



public sealed class SimpleReportServerConnection : IReportServerConnection2

{



public WindowsIdentity ImpersonationUser

{

get

{

// Use the default Windows user. Credentials will be

// provided by the NetworkCredentials property.

return null;

}

}



public ICredentials NetworkCredentials

{

get

{

// Read the user information from the web.config file.

// By reading the information on demand instead of

// storing it, the credentials will not be stored in

// session, reducing the vulnerable surface area to the

// web.config file, which can be secured with an ACL.



// User name

string userName =

ConfigurationManager.AppSettings

["MyReportViewerUser"];



if (string.IsNullOrEmpty(userName))

throw new Exception(

"Missing user name from Web.config file");



// Password

string password =

ConfigurationManager.AppSettings

["MyReportViewerPassword"];



if (string.IsNullOrEmpty(password))

throw new Exception(

"Missing password from Web.config file");



// Domain

string domain =

ConfigurationManager.AppSettings

["MyReportViewerDomain"];



if (string.IsNullOrEmpty(domain))

throw new Exception(

"Missing domain from Web.config file");



return new NetworkCredential(userName, password, domain);

}

}



public bool GetFormsCredentials(out Cookie authCookie,

out string userName, out string password,

out string authority)

{

authCookie = null;

userName = null;

password = null;

authority = null;



// Not using form credentials

return false;

}



public Uri ReportServerUrl

{

get

{

string url =

ConfigurationManager.AppSettings[

"MyReportServerUrl"];



if (string.IsNullOrEmpty(url))

throw new Exception(

"Missing url from the Web.config file");



return new Uri(url);

}

}



public int Timeout

{

get

{

return 60000; // 60 seconds

}

}



public IEnumerable<Cookie> Cookies

{

get

{

// No custom cookies

return null;

}

}



public IEnumerable<string> Headers

{

get

{

// No custom headers

return null;

}

}



}

}

Wednesday, November 14, 2007

ASP.NET interview Architecture/Design questions


1) What is the difference between MVC architecture and three tier architecture?
2) What technology would you use to transfer data between two ASP.NET applications ensuring a loosely coupled architecture for the data transfer?
3) Architect a solution to ensure a record being updated in the database is locked from all users until the update is complete. How will you deal with browser closing and page change issues if the user does not complete the update?
4) How can I ensure that a method in the class is only available when it is instantiated and not when it is inherited?

Monday, September 03, 2007

Secret tools of top .Net development teams.

Ever been annoyed with challenges of developing enterprise class applications in team environments? While building a seamless development team might be beyond the scope of this article, here are a few tools that can increase productivity by leaps and bounds. And the best part is they are all free, open source tools that most developers are hardly ever aware of.

1) Source control is a key tool in your toolbox, it can help version your code prevent loss of valuable code allow multiple developers to work on the same code base etc. Even if you are a single developer you will find it immensely useful. SVN, CVS and Visual source safe are a few source control repositories. Again you may want to evaluate them to suite your needs based on how they work and features they support.

2) Automated building, unfortunately the feature that is most lacking with Visual Studio 2005 (at least for the free, std and prof editions) is the lack of support for automated continuous/integrated building of code. Just imagine if every time each developer on the team checked in a feature enhancement or a bug fix your Project Managers would have to bring the roof down with umpteen meetings, testing, and deployment.

But if you checkout the latest version of your code build it and run automated testing without a single mouse click, how cool would that be? I bet you'd impress the boss and spend more time tanning than frying your eyes by the monitor. You think its a myth, but you can do just that by using Cruise control and MSBuild. What's even more cool is that you can integrate Cruise control with SVN, so automated builds are being generated on the latest code base that has been checked in.

3) Most challenges with software development are shipping bug free or nearly bug free code. While even the best Q.A teams can miss the most common of bugs. Automated testing can prove to be less expensive and far more useful than repeated manual testing. Especially in the case of regression testing, you are not going to bore your testers to death. NUnit testing is a good unit testing tool to use. Further you can integrate Nunit testing with Cruise control.

4) Bug tracking - a good bug tracking system can prove to be more than just another Pandora's box if you can use it wisely. While it does not play a direct role in team development it can help developers track and fix their bugs.


Happy Anniversary PriceCanada.com!