Tuesday, April 23, 2013

How to host a Nest ASP.Net applicaiton within the same source code.

I encounter an issue when i try to use the same source code to create a sub web application under

the current web application. the following picture will show the scenario that i want to acomplish






then i will receive the follow 500 Error




after i google  the web and do some research the following will solve the issue

this link will provide me great help in solving my problem

http://stackoverflow.com/questions/782252/avoid-web-config-inheritance-in-child-web-application-using-inheritinchildapplic

I must stop the nested child application inherit System.Web and System.WebServer configuration from the parent which is the source.

<location path="." inheritInChildApplications="false">
  <system.web>
   <compilation debug="true" targetFramework="4.5"/>
   <httpRuntime targetFramework="4.5"/>
   <pages controlRenderingCompatibilityVersion="4.0" clientIDMode="AutoID">
    <controls>
     <add tagPrefix="telerik" namespace="Telerik.Web.UI" assembly="Telerik.Web.UI"/>
    </controls>
   </pages>
   <httpHandlers>
    <add path="Telerik.Web.UI.WebResource.axd" verb="*" type="Telerik.Web.UI.WebResource, Telerik.Web.UI" validate="false"/>
   </httpHandlers>
   <httpModules>
    <add name="RadCompression" type="Telerik.Web.UI.RadCompression"/>
   </httpModules>
   <!--<httpRuntime maxRequestLength="92160000" executionTimeout="112"/>-->
   <identity impersonate="false"/>
  </system.web>
 
  <system.webServer>
   <validation validateIntegratedModeConfiguration="false"/>
   <modules runAllManagedModulesForAllRequests="true">
    <add name="RadCompression" type="Telerik.Web.UI.RadCompression"/>
   </modules>
   <handlers>
    <remove name="Telerik.Web.UI.WebResource.axd" />
    <add name="Telerik.Web.UI.WebResource.axd" path="Telerik.Web.UI.WebResource.axd" verb="*" type="Telerik.Web.UI.WebResource, Telerik.Web.UI" preCondition="integratedMode"/>
    <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit"/>
    <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit"/>
    <remove name="ExtensionlessUrlHandler-Integrated-4.0"/>
    <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0"/>
    <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0"/>
    <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>
   </handlers>
   <security>
    <requestFiltering>
     <requestLimits maxAllowedContentLength="943718"/>
    </requestFiltering>
   </security>
   </system.webServer>
 </location>
















Wednesday, March 20, 2013

How to solve Case Insensitive Issue in DB2 Query

we all know that SQL Server are case insensitive. when we implement the stored procedure, we did not worry about the filter criteria in the where clause.

I encounter an very strange error that use must use the correct format criteria when they run the application to search the database. the root cause of this issue is DB2 is case insensitive by default.

here is a work around to solve this issue. we can convert the filter column value to either upper case or lower case.


Select column1, column2 from DB2 Table
Where Upper(column1)=Upper(criteria one) and Lower(column2)=Lower(Criteria)

after I use the upper and lower function to convert the column values and filtered value in the stored procedure. now My Search application will ignore the case sensitive in the search input.

How to maintain Footer Link using Sharepoint List in Sharepoint 2013 Publishing Site

Since Web Content Management is one of the great feature in all version of SharePoint.  the basic version of sharepoint which foundation foundation already contain this great feature.

here i will show you it is very convenient if you have public facing web site running under SharePoint foundation. the user can easily maintain the footer navigation link of web site.


First we will create two custom site columns that associated with footer Link. one is the status site column which will allow user to temporarily turn on and off the link.  another one is the sort site column. this feature will let the user to change the link position in the footer link section.

Elements.xml of Status Column which inherits from Boolean Field Type. it will show as a checkbox to let the user check or uncheck to enable or disable the display of link.

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">  
  <Field
       ID="{dd0b38e8-6cee-4135-ad6f-88a62aa84e4c}"
       Name="StatusColumn"
       DisplayName="Status"
       Type="Boolean"
       Required="TRUE"
       Group="Custom Site Columns">
  </Field>
</Elements>


add new Site column named Sort to the project and make it inherits from the Text Field Type. the user can input integer to indicate its position in the footer navigation links section.

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">  
  <Field
       ID="{30701fa1-a7f5-4ece-bba0-2e44836b1c3f}"
       Name="SortOrder"
       DisplayName="Sort Order"
       Type="Text"
       Required="TRUE"
       Group="Custom Site Columns">
  </Field>
</Elements>

add new content type to the project and choose this content type to inherit from Item




Add those columns to the custom content type. as shown in the picture below

add new visual web parts to the project and modify the layout by adding the datalist asp.net control to

<div style="text-align:center;">
    <div style="width:600px; margin-left:auto; margin-right:auto;">
    <asp:DataList ID="dlFooterLink" runat="server" RepeatDirection="Horizontal">
        <ItemTemplate>
            <asp:HyperLink runat="server" Font-Underline="true"  Text='<%# "["+DataBinder.Eval(Container.DataItem,"Title")+"]" %>' 
            NavigateUrl='<%# DataBinder.Eval(Container.DataItem,"Url") %>'></asp:HyperLink>         </ItemTemplate>     </asp:DataList>     </div> </div>

in the code behind, we will implement the business logic that handle the sorting the order of each link and filter out those links with inactive status. In the page loading event,

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
    using (SPSite spSite = new SPSite(SPContext.Current.Web.Url))
    {
        using (SPWeb spWeb = spSite.OpenWeb())
        {
            SPList footerLinkList = spWeb.Lists["test"];
            SPQuery spQuery = new SPQuery();
            spQuery.ViewFields = " <FieldRef Name='Title' /><FieldRef Name='URL' />";
            spQuery.Query = @"<Where><Eq><FieldRef Name='StatusColumn' /><Value Type='Boolean'>1</Value></Eq></Where>
                <OrderBy><FieldRef Name='SortOrder' /></OrderBy>";
            spQuery.ViewFieldsOnly = true;
            SPListItemCollection spListItems = footerLinkList.GetItems(spQuery);
            if (spListItems != null)
            {
                SPFieldUrlValue urlValue = new SPFieldUrlValue();
                //DataTable dt = new DataTable();
                //dt = spListItems.GetDataTable();
                var footerLinkItems = new List<FooterLink>();
                foreach (SPListItem spListItem in spListItems)
                {
                    urlValue = new SPFieldUrlValue(spListItem["URL"].ToString());
                    footerLinkItems.Add(new FooterLink()
                    {
                        Title = spListItem["Title"].ToString(),
                        Url = urlValue.Url
                    });
                }
                dlFooterLink.DataSource = footerLinkItems;
                dlFooterLink.DataBind();
            }
        }
    }
}
}

the code to handle the filter action

<Where><Eq><FieldRef Name='StatusColumn' /><Value Type='Boolean'>1</Value></Eq></Where>

the snippet of code that implement the sorting the position of links

<OrderBy><FieldRef Name='SortOrder' /></OrderBy>


since there is a URL column in the SharePoint which will store the navigation url of each link and  the format of URL is "www.yahoo.com, www.yahoo.com". if we just binding this column to the navigation url property of hyperlink control. the click action will failed due the incorrect format of url. the following code will solve this issue

 urlValue = new SPFieldUrlValue(spListItem["URL"].ToString());
 Url = urlValue.Url
then build and deploy. Now we can add this FootLinkNavigation Web Part to the bottom of the web page, when I click on the new item button on the ribbon toolbar. the page will loaded the following page.


after you removed the default content that associated with custom list. and added the custom content type to be the default content type of the custom sharepoint list.

the sample list that store all navigation links in the footer section

the sample web part to show the footer navigation section



 
 
 

Thursday, February 7, 2013

How to fix error "Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. "

the application worked well when it was run in the .net framework 3.5 and asp.net 2.0 environment.

today i upgrade the application to

"Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near ' "




the root cause of this issue is that UpdatePanel control will cuase the conflict with asp.net 4.5 synchronization.

AssociatedUpdatePanelID="UpdatePanel1"
                runat="server">
                <ProgressTemplate>
                    <%--<img alt="progress" src="images/loading.gif" />
           Processing...           --%>
                    <div id="progressBackgroundFilter"></div>
                    <div id="processMessage">
                        <img alt="Loading" src="images/loading.gif" />updating......
                    </div>
                </ProgressTemplate>
            </asp:UpdateProgress>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
              

I had to specific which control had trigger the update and cause the error inside the update control panel to fix the issue. 

               <Triggers>
                    <asp:PostBackTrigger ControlID="lnkBtnSave" />
               </Triggers>

AssociatedUpdatePanelID="UpdatePanel1"
                runat="server">
                <ProgressTemplate>
                    <%--<img alt="progress" src="images/loading.gif" />
           Processing...           --%>
                    <div id="progressBackgroundFilter"></div>
                    <div id="processMessage">
                        <img alt="Loading" src="images/loading.gif" />updating......
                    </div>
                </ProgressTemplate>
            </asp:UpdateProgress>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <Triggers>
                    <asp:PostBackTrigger ControlID="lnkBtnSave" />
               </Triggers>
              <ContentTemplate>
                </ContentTemplate>
            </asp:UpdatePanel> 
 
 
 

Monday, January 28, 2013

How to fix asp.net configuration Error

I try to upgrade my previous project from .Net Framework 2.0, 3.0 and 3.5 to the latest
.Net Framework 4.5.

Server Error in '/MyOldApp' Application.

Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: Unrecognized attribute 'targetFramework'. Note that attribute names are case-sensitive.

Source Error:

Line 14:   -->
Line 15:   <system.web>
Line 16:     <compilation targetFramework="4.5"/>
Line 17:     <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
Line 18:       <controls>

Source File: C:\Development\Intranet\MyApp\web.config Line: 16


Version Information: Microsoft .NET Framework Version:2.0.50727.3623; ASP.NET Version:2.0.50727.3618 


the root cause of this issue is that all my application had been configured  to run windows authentication and run under the application pool that configure with service account.

when i set up the application pool, it was configured to run in the asp.net 2.0 environment. 
as a result, i will get the above error when i deployed my upgrade code to staging environment.

after i create a new applicaiton pool running in .net framework 4.0. the configure error is fixed.

Friday, January 25, 2013

How to fix "Could not load file or assembly 'Newtonsoft.Json' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded."

Today i got a very weired error as following
"Could not load file or assembly 'Newtonsoft.Json' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded."


when i check my project properties, under the application tab. the target framework had been
set to .Net Framework 3.5














the root cause of this issue is that new library
using System.Net.Http; 
using System.Web.Script.Serialization;  
that Newtonsoft.Json depends on are  Available at the .Net Framework 4.0 or 4.5.
after i switched to the latest .Net Framework.the project compile and the page was launched.