Wednesday, March 11, 2009

Web setup project - content files - Vs.net 2008

Problem
In one of my project, I had Vs.net 2008 web project including multiple c# projects. 

I create a web setup project in the same solution but when deployed I noticed that PDF files are not included in the deployment. (Not webdeployment project)

Solution
By default, VS.net  project do not include PDF files as content files. (.js, .css, .jpg ... are included by default)

I posted on forums, and the solution is ...

Approach 1: Mark the file as content. Right click the file in Vs.net 2008, properties, set build action -> Content. You may have to do for every file. 

In other words, modify your web application's project file to set pdf files to "Content" by

<ItemGroup>

    <Content Include="YourFolder\Reference1.pdf"/>

     <Content Include="YourFolder\Reference2.pdf"/>

 ......

</ItemGroup>

 Using IDE does the modification for you.


Aprroach 2: Mark the whole folder to copy ...

If these pdf files are in one folder, we can try to use MSBuild to copy this folder to OutPut directory in Web Deployment project.

To do so, we need to enter Web Deployment project file by right clicking Web Deployment project in Solution Window and selecting "Open Project File", and then write following command below "Import" section:

<Target Name="AfterBuild">

<Copy DestinationFolder="YourDestinationfolder" SourceFiles="YourSourcefile"></Copy>

</Target>  

Example

<Copy DestinationFolder="Guides" SourceFiles="Guides\*.pdf"></Copy>

Or

<Copy DestinationFolder="$(OutputPath)\Guides\" SourceFiles="$(SourceWebPhysicalPath)\Guides\*.pdf"></Copy>

Asp.net - Cross page posting

Cross page posting

New feature in Asp.net 2.0

Why? When?
Some pages need to post the page to other page (like good old systems or old classic asp) or when there is a need to have multiple submit button controls, where one may need to submit to other page.

Who decides?
It is mostly the developer that decides to use this feature or not.
It is heavy duty control and be careful to use this feature.

How to use it?
Please refer MSFT article first.
http://msdn.microsoft.com/en-us/library/ms178139.aspx
http://msdn.microsoft.com/en-us/library/ms178140(VS.80).aspx

Secondly use strong typing both at control level and page level attributes.
PreviousPage != null && PreviousPage.IsCrossPagePostBack 
Login LoginControl = (Login)PreviousPage.FindControl("Login1");
<%@ PreviousPageType VirtualPath="~/SourcePage.aspx" %> 

Example of scenarios to use cross page posting
  • We can have search control in the header and a regular form in the content page.
  • We have to submit to different page based on a button type clicked.
  • To better use of caching some times, we provide forms say for search, in one page and submit to other page ...
  • For those who like old style of submitting to different pages ... like in classic asp
Note: It is all deponds the scenario, developer to decide why we need this feature.

For ex: One of the project, application site home page needs to be served very fast and I decided to use by enabling the cache (vary by browser) and did the cross page posting to validate the login information. The reason in my case are the login process is complicated with lot of server validation, roles assignment, license verification, rules and redirection ... 

Drawbacks
Say, if you are validating a form on server side, it is hard to get back to the previous page.