// April 19th, 2007 // No Comments » // .net, asp.net
I was recently migrating a project from a Website Project to a Web Application Project (WAP) in Visual Studio 2005. This is completely new to me, since I’m mostly a Middle Tier fan. So we had extensive use of Profiles in our Website project, and when migrating the application broke. Specifically code that was in Code Behind had compilation errors while trying to find the Profile object.
Since this object is compiled and instantiated at run-time, VS didn’t seem to find it. So this I spent several hours trying to find a solution, and the only one I could figure out, was to write the damn Profile class, and included it in my project, so I began doing that., when I was about finished with my Profile implementation, I found this article.
As it seems the main reason why this doesn’t work is because of the way Web Applications are compiled. This is the complete answer provided by one of the Asp.Net Team in this forum:
This is not so much a bug as a difference in compilation models between web sites and web application projects. See the profile topic in the following for some more info:
http://webproject.scottgu.com/CSharp/Migration2/Migration2.aspx
The basic issue is that profiles are compiled dynamically by ASP.Net. In web sites your code files are also compiled dynamically by ASP.Net. So, ASP.Net is able to first compile the profiles and then add an accessor and reference to your page and compile it afterwards. In Web Application Projects your code files are compiled on the client. They can not have references to dynamically created assemblies that do not exist or they will not compile.
This is a general issue for ASP.Net BuildProviders and and Web Application Projects. We do not have a general solution yet. The two build providers we get the most questions about are App_GlobalResources and Profiles. For these two we are trying to come up with solutions. The thought is that we will generate proxy opjects that get compiled into your assembly on the client. The proxy objects for profiles will represent the state of the profiles in web.config at the time of compilation on the client. You will have strongly typed access to the profiles through the proxy. The proxy will work something like the sample code in the link above.
Tim McBride
This posting is provided “AS IS” with no warranties, and confers no rights.
Also in that forum, there is an Add-in to generate the Profile for Web Applications. I already installed it and tested, it works like a charm. It is not as seamless as I would like, since I have to instantiate the the Profile for each page, but it works. The Add-in is here.
I hope this helps, because I spent too many hours looking for a solution. And there is not enough information to make it work correctly.
Tweet This Post