Luuuukke.NET

Bugs, headache, lost hairs... I love IT

Could not load file or assembly 'AjaxControlToolkit Culture=neutral, PublicKeyToken=or one of its dependencies. The parameter is incorrect…

clock July 11, 2011 21:24 by author Luuuukke

Got this message,  checked all files… deleted the solution file, re-linked all projects & references… nothing was helping.

And this error suddenly came after my computer crashed (overheating, nut that’s another problem).

 

Hey, but wait…. the computer crashed while visual studio was building the solution…
The problem was easily solved by deleting asp.net framework temporary files Smile

 

image



Unable to update the EntitySet

clock June 24, 2011 14:22 by author Luuuukke

If you get this Error with Entity Framework:

Unable to update the EntitySet {EntityName} because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation.

Just check that the table have a PrimaryKey assigned…
And do not forget to update your datamodel after adding the key.Winking smile



Visual Studio 2010 crashes on exit

clock February 4, 2011 10:07 by author Luuuukke

Visual studio was consistently crashing when exiting, with 2 specifics solutions…
I had to close all documents, collapse all sub projects, and select the solution in the Solution explorer to avoid VS to crash… Steaming mad

image

 

Yesterday, I found the cause: one child class library project was set to compile in asp.Net 2.0,
while all other projects were set to compile for asp.Net 4.0…

image

 

To change the target framework of a class library project,
open its properties,
select the tab “compile”,

go to the advanced options :

image

 

And select the target network:

image

 

That’s all folks Hot smile



Custom Sitemap Provider Localization

clock January 24, 2011 10:06 by author Luuuukke

Sitemap Providers are a nice feature of asp.NET 2.0, especially with the possibilities to develop your own custom providers.

One problem I faced is the ability to localize title, description .. for my custom provider.
After goggling a lot, I found… that I was not alone with that problem, and that nobody had posted the solution online

(The only solutions that I found were quirky fixes, like programmatically parsing the sitemap nodes title at page load, without using the built-in localization system…)

I found tips here .. And the solution is darn easy:

In your custom provider, in the method

Public Overrides Function BuildSiteMap() As System.Web.SiteMapNode

Load your sitemap nodes using the following method

Public Sub New( _
ByVal provider As SiteMapProvider, _
ByVal key As String, _
ByVal url As String, _
ByVal title As String, _
ByVal description As String, _
ByVal roles As IList, _
ByVal attributes As NameValueCollection, _
ByVal explicitResourceKeys As NameValueCollection, _
ByVal implicitResourceKey As String _
)

 

instead of the commonly used method

Public Sub New( _
ByVal provider As SiteMapProvider, _
ByVal key As String, _
ByVal url As String, _
ByVal title As String
)

In my case in use the implicitResourceKey to pass the resource name,
and my custom localization provider (sql resources) does the rest…

Dim node As New SiteMapNode(Me, key, url, title, string.empty, Nothing, Nothing, Nothing, {title resource name})

 

And then tell your application that your custom sitemap is localized by setting the enableLocalization="true"

<siteMap defaultProvider="MyCustomSiteMapProvider" enabled="true">
            <providers>
                    <add name="MyCustomSiteMapProvider" type="MyCustomSiteMapProviderType, MyCustomSiteMapProviderType.dll"  enableLocalization="true"/>
                      </providers>
        </siteMap>
 

 

Edit 30 Jan. : the first visitor coming on a page receives the correct language, but then the sitemap does not localize to the other languages!!!
I gave up, and now I populate the nodes’ text at runtime…

Protected Sub TopMenu_MenuItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MenuEventArgs) Handles TopMenu.MenuItemDataBound
Dim n As SiteMapNode = CType(e.Item.DataItem, SiteMapNode)
Dim title As String = GetGlobalResourceObject("resource", n.ResourceKey)
e.Item.Text = title 
End Sub


System.DBNull when reading excel file

clock December 12, 2010 17:43 by author Luuuukke

If you get DBNull values when reading an excel fil through Microsoft.Jet.OLEDB provider, although cells contain values
there is a simple trick: add a parameter "IMEX=1" to the connection string, to force the cells to be read as text ...

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=FileName.xls;Extended Properties="Excel 8.0;IMEX=1"

 

 

 



Visual Studio XML IntelliSense for URL Rewrite

clock December 12, 2010 17:30 by author Luuuukke

With the new IIS 7 integrated configuration model, you may want to use the add-in URL rewriting

Unfortunately, Visual Studio intellisense does not natively understand the rewrite tags...
So you need to update the schema.. See http://ruslany.net/2009/08/visual-studio-xml-intellisense-for-url-rewrite-1-1

To install this schema, you will need to execute a C# Script "cscript UpdateSchemaCache.js",

On my windows 7 , I was not able to run that script, and received the error: There is no script engine for file extension "js"

The solution is here:
http://www.winhelponline.com/articles/230/1/Error-There-is-no-script-engine-for-file-extension-when-running-js-files.html

You need to register the jscript.dll and apply and patch...

Enjoy :-)



Automatically encrypt connection strings in web.config

clock September 18, 2010 17:06 by author Luuuukke

Following the recent discovery of this asp.NET security flaw, i checked all my production web.config to set the correct custom errors,
and also to verify that connection strings are encrypted.

As you certainly now, you can do it on the server with the aspnet-regiis.exe command..;
but you have to run it manually, and take care not to upload an unencrypted web.config later... not very practical when you manage dozens of websites...

As there is an easy way to encrypt web.config section programmatically,
i found wise to have the application_start check that the connectionString is encrypted, and do it automatically otherwise...

Sub Application_OnStart()
        
        Dim config As Configuration = WebConfigurationManager.OpenWebConfiguration(HttpRuntime.AppDomainAppVirtualPath)
        Dim section As ConfigurationSection = config.GetSection("connectionStrings")
            If (section.SectionInformation.IsProtected) = False Then
                section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider")
                config.Save()
            End If
                          
End Sub

 

To avoid encrypting the connection on the development server, i simply added a test and a key in the appsettings...

    Sub Application_OnStart()
        
        If ConfigurationManager.AppSettings("AutomaticallyEncryptConnectionStrings") Is Nothing _
        OrElse CType(ConfigurationManager.AppSettings("AutomaticallyEncryptConnectionStrings"), Boolean) = True Then
            
            Dim config As Configuration = WebConfigurationManager.OpenWebConfiguration(HttpRuntime.AppDomainAppVirtualPath)
            Dim section As ConfigurationSection = config.GetSection("connectionStrings")
            If (section.SectionInformation.IsProtected) = False Then
                section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider")
                config.Save()
            End If
        End If

                   
    End Sub

appsettings key :

    <appSettings>
        <add key="AutomaticallyEncryptConnectionStrings" value="false"/>      
    </appSettings>

 

Please note that i used HttpRuntime.AppDomainAppVirtualPath and not  Request.ApplicationPath,
because there is no context available in Application_start when running in integrated mode

 

Now I can again sleep soundly... Wink



ASP.NET Custom Errors Security Flaw

clock September 18, 2010 13:25 by author Luuuukke

There is a serious security flaw in asp.net framework, that should be adressed immediately.

This hole was revealed some hours ago by microsoft, see ASP.NET vulnerability, and could allow an attacker to access any file on the website,
including sensitive information (database connection strings, web.config)

Microsoft security advisory
Test script to run on the server to check vulnerabilities

The workaround is rather simple: be sure to set all custom errors to "on" and to a single file

<configuration>       

   <system.web>

      <customErrors mode="On" defaultRedirect="~/error.html" />

   </system.web>       

</configuration>

read more about the workaround

btw, i took the occasion to check that all my connection strings are encrypted on the production server...
easy to do with aspnet-regiis.exe

-- Concrete example of encrypting the Web.config file for a particular website...
aspnet_regiis.exe -pef "connectionStrings" "C:\Inetpub\wwwroot\MySite" –prov "DataProtectionConfigurationProvider"

More info about encrypting connection strings

A great post with More information about the flaw, including a demo of a possible attack

 

Of course, i immediately patched my client's websites... Cool



Error: "Cannot use a leading .. to exit above the top directory..."

clock August 31, 2010 20:08 by author Luuuukke

I was getting this error on url rewrites for url containing multiples "/xxx/xxx" with url rewriter...

After being stuck with this error on a new app with multiple masterpages & rewriting,
I found this article and this one, about themes images not displayed when rewriting, but also about the "cannot.... bla bla"

"Rewriting pathes with slashes ("/") in it can lead to this f... erro "Cannot use a leading ..." error when running the website within IIS."

Bingo ! it works ! One hyperlink by one, i set the ImageUrl programmatically for my masterpages,
and the error disappeared when i eventually set the ImageUrl in code for a child user control i use in a masterpage...

So, set the hyperlink's ImageUrl property programmatically for masterpages & controls, That's all Cool

Note that i sometimes get this error from opnline app when browsed by crawlers;..
I tried evrything, ith browser caps and so on.. nothing worked.
Gonna give this a try too :-)

 



Minify css and jss files automatically with Visual Studio Web Deployment Projects

clock August 29, 2010 16:38 by author Luuuukke

After googling for some time, i finally found the perfect solution to minify css stylesheets and javascripts .js files.
I wanted to automaticaly compress releases files when building my websites, using web deployment projects...

The solution uses the Yahoo YUI Compressor, especially the compressor for .NET release,
(see the sample web deployment project solutions in the other downloads available !)

to put it into work, edit the web deployment project as following:

add a reference to the YUI Compressor on top of your project file:

<UsingTask TaskName="CompressorTask" AssemblyFile="..\{path to the YUI Compressor}\Yahoo.Yui.Compressor.dll" />

Then add an item group to select the input css & js files, and a compressor task in the After merge event

<Target Name="AfterMerge">

<ItemGroup>
<
CssFiles Include="$(TempBuildDir)App_Themes\**\*.css;$(TempBuildDir)CSS\*.css" />
<
JavaScriptFiles Include="$(TempBuildDir)\JavaScript\*.js" />
</
ItemGroup>

<CompressorTask
CssFiles="@(CssFiles)"
DeleteCssFiles="No"
CssOutputFile="%(rootdir)%(directory)%(Filename)%(extension)"
CssCompressionType="YuiStockCompression"
JavaScriptFiles="@(JavaScriptFiles)"
ObfuscateJavaScript="FoSho"
PreserveAllSemicolons="Yeah"
DisableOptimizations="Nope"
EncodingType="Default"
DeleteJavaScriptFiles="No"
JavaScriptOutputFile="%(rootdir)%(directory)%(Filename)%(extension)"
LoggingType="ALittleBit" />

</Target>

 

More information about the MSBuild selectors, commands, ...: http://msdn.microsoft.com/en-us/library/ms171452(VS.80).aspx



Sign in