Could not load file or assembly 'WebGrease, Version=1.5.1.25624

by pinkbegemot 14. March 2015 13:27

Could not load file or assembly 'WebGrease, Version=1.5.1.25624, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x8013

 

This error may occur on a production server (IIS 7 in my case), while everything works fine in your development environment (VisualStudio 2012), even if you use IIS and not the bulit-in ASP.NET Development server.

What happens is, when you upgrade the  NuGet package  in VisualStudio 2012, VS adds the following  block to the web.config file in your project: (inside the <configuration/> ælement). This is an example from my own file:

  <runtime>

    <assemblyBindingxmlns="urn:schemas-microsoft-com:asm.v1">

      <dependentAssembly>

        <assemblyIdentityname="System.Web.Optimization"publicKeyToken="31bf3856ad364e35"culture="neutral"/>

        <bindingRedirectoldVersion="0.0.0.0-1.1.0.0"newVersion="1.1.0.0"/>

      </dependentAssembly>

      <dependentAssembly>

        <assemblyIdentityname="WebGrease"publicKeyToken="31bf3856ad364e35"culture="neutral"/>

        <bindingRedirectoldVersion="0.0.0.0-1.1.0.0"newVersion="1.5.1.25624"/>

      </dependentAssembly>

    </assemblyBinding>

  </runtime>

As long as everything works  on the development machine, we don’t think about the actual version of the  WebGrease.dll being used by the runtime. You might have several of them on your development machine. I have tried to  manually remove the reference to the  WebGrease.dll, then add it again to the project, but the actual version No in the above-mentioned block in web.config remained unchanged.
That is why for some time I didn’t pay attention to the fact, that the actual version of the WebGrease.dll in my project BIN folder was 1.6.x.x,. This version was also copied to the production environment.

I have read A LOT of tweaks about this issue, NONE of them worked for me. For instance, removing  xmlns="urn:schemas-microsoft-com:asm.v1"  in the top line.
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> changed nothing, but I am glad, if it  worked for he others.

Some guys out there @ Stackoverflow shared an impression, the whole block is simply being ignored by the runtime, and I had such an impression, too. 
There are also  tips, advising to remove the complete block <assemblyBinding></assemblyBinding> from the web.config file, but this doesn’t work, either. 

So, finally, I have figured out, the error message/exception must be accurate – the runtime simply can’t find the version specified in the web.config.

Thus, I suggest you check the actual version of the WebGrease.dll in the BIN folder of your project and put this version No into your bindingRedirect directive as   the new version:

        <bindingRedirectoldVersion="0.0.0.0-1.6.5135.21930"newVersion="1.6.5135.21930"/>

That should work, as it did for me. Happy coding!

Facebook Logout combined with ASP.NET application logout

by pinkbegemot 7. May 2013 13:14

 

OBJECTIVE

You want to Login/Logout your user with just one click, regardless of the user being a FB user or your web site user. You don't want  your users to use Facebook logout button

 

SCENARIOS

a. You have an ASP.NET web site, utilizing ASP.NET Forms authentication and also want to use Facebook Login /Logout functionality

b. You have multiple ASP.NET web sites and want to use “single sign on” for all of them, combining ASP.NET Forms  authentication with Facebook Login.

 I have tested this approach with the following IIS 7 setup:
one  root web application, one sub-application and one virtual directory (both under the root web application)

PREREQUISITES

I presume you already know about the Facebook SDK for .NET.
If not, follow the instructions here:
http://facebooksdk.net/docs/web/getting-started

To be able to try the steps, described below, you must have a web application with Facebook Login enabled and tested, so you know it works.

 To implement Single Sign On, you basically need to configure your web sites with the ASP.NET Memberhsip and Role providers and point them to a common database.  In the Scenario B that’s easy to achieve as all three web sites share one master  “Web.config” file. Here is an example from my working solution:

  <authenticationmode="Forms">

      <formscookieless="UseCookies"loginUrl="/YourVirtualDirectory/Account/Login.aspx" />

    </authentication>

    <machineKeydecryptionKey="AutoGenerate"validation="SHA1"validationKey="AutoGenerate" />

 

Facebook Logout combined with application logout

In case of Scenario B (three web applications sharing same user credentials) the  biggest challenge would be to implement  a single Logout.

The method, described in FB Developer’s tutorial shows how to implement  a combined Login, using a generic HTTP handler “FacebookLogin.ashx” class.

 

public class FacebookLogin : IHttpHandler, System.Web.SessionState.IRequiresSessionState{

 public void ProcessRequest(HttpContext context){

        var accessToken = context.Request["accessToken"];

        if (accessToken != null){

            HttpContext.Current.Session["accessToken"] = accessToken;
            ..

       }

}}

But the user’s AccessToken, stored in Session will be only available for the login-application and not for the other ones, if the user should fancy logging off  from another site.

Therefore, it can be implemented, storing the AcessToken as a variable in a common helper class, available for all your applications.
In the following code snippets I call it “MyCommonClass”.

 Facebook Login.ashx

 public class FacebookLogin : IHttpHandler, System.Web.SessionState.IRequiresSessionState{

public void ProcessRequest(HttpContext context){

        var accessToken = context.Request["accessToken"]; 

        if (accessToken != null){
            HttpContext.Current.Session["accessToken"] = accessToken;
              MyCommonClass.accessToken = accessToken; // added code

             ..

        }}}

 

 Login.aspx.cs

  protected void Page_Load(object sender, EventArgs e) {

// Do you stuff here in case of log in
         #region logoff

            if (this.Request.QueryString.ToString() == "logoff") {

                 /** Sign out off your app * */

                SignOut();

               // in case of FB login

                string accT = null;

                if (Session["accessToken"] != null)

                    accT = Session["accessToken"].ToString();

                 else{

                    accT = MyCommonClass.accessToken;

                }

       if (this.Request.UrlReferrer != null && this.Request.UrlReferrer != this.Request.Url){

                     string redirectUrl = this.Request.UrlReferrer.ToString();

                     // in case of FB login

                     if (MyCommonClass.IsFbUser(Membership.GetUser().UserName))

                        if (accT != null)

                            Response.Redirect(LogOut(accT, redirectUrl));

                        else{

                           Response.Redirect("/MyVirtualDir/FacebookLogout.ashx", true);

                          }

                       else

                        this.Response.Redirect(redirectUrl, true);

                }

                return;

            }

            #endregion

 }

  protected string LogOut(string accessToken, string url) {          // FB logout

             var oauth = new FacebookClient();

            var logoutParameters = new Dictionary<string, object>{

                     {"access_token", accessToken},

                      { "next", url}

           };

            var logoutUrl = oauth.GetLogoutUrl(logoutParameters);

            return logoutUrl.ToString();

   }

 
 protected void SignOut(){                                          // App logout

     FormsAuthentication.SignOut();

     HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, string.Empty);

     cookie.Expires = DateTime.Now.AddYears(-3);
     HttpContext.Current.Response.Cookies.Add(cookie);
 }

 

Facebook Login.ashx

 

public class FacebookLogout : IHttpHandler {

        public void ProcessRequest(HttpContext context) {

            var accessToken = MyCommonClass.accessToken;   

             if (accessToken != null) {

                 string url = context.Request.UrlReferrer.ToString();

                 LogOut(accessToken);

                 MyCommonClass.accessToken = null;

                context.Response.Redirect(url);

            }

        }

   protected void LogOut(string accessToken) {

            var oauth = new FacebookClient();        
            var logoutParameters = new Dictionary<string, object>{

                     {"access_token", accessToken},

                      { "next", ""}

                  };

            var logoutUrl = oauth.GetLogoutUrl(logoutParameters);    

         }

 

 

BlogEngine 2.6: Non-primary blog issues

by pinkbegemot 3. April 2013 14:03

 

When you create a new blog as a non-primary one some features of the  BlogEngine 2.6 won’t work, though you can’t discover it right away. But the good news is that it can be tweaked!  So far I have discovered the following issues for a non-primary blog:

  • Widget zone doesn’t work
  •  File upload fails
  •  Globalization stumbles

 Widget zone doesn't work on update

SyMPTOMS

You want to add widgets to a WidgetZone in a non-primary blog. The widgets get added, but when you hit  F5 to refresh the page the widgets are not rendered.

The trouble is with the “BlogEngine.Core.Blog. CurrentInnstance” variable – it is supposed to return the current instance, but it doesn’t always do so (contrary to our expectations).
If you debug the application (setting break points at numerous calls to “BlogEngine.Core.Blog. CurrentInnstance” inside the “WidgetZone” framework classes and in the “Global.asax.cs” ) you will discover that you get the correct instance returned on the first two calls. But as the execution continues, the return value changes and starts pointing to the primary blog. This happens during requests for scripts files, styles, etc. which is accurate, in fact. But this value also gets passed to your WidgetZone  cache, which results in actual adding the widgets to the primary blog’s WidgetZone, but rendering  the cached version of your non-primary blog’s WidgetZone.

RESOLUTION

1.       The workaround I had to put up with is to make some changes in the code to force  BlogEngine always return the primary blog instance as far as the WidgetZone’s rendering is concerned.

  1.  Add a new method to the “BlogEngine.Core.Blog.cs”. It will return your primary blog.

       public static Blog PrimaryBlog{
               
    get { return _primary jQuery152020093221597779243_1364990635002 (_primary = blogs.FirstOrDefault(b => b.IsPrimary))};  
         

  2. Search for  all “Blog.CurrentInstance” calls in all the classes in the WidgetZone framework .

    In the BlogEngine .NET files:

    admin\WidgetEditor.aspx.cs

    App_Code\Controls\WidgetBase.cs
    App_Code \Controls\WidgetEditBase.cs
    App_Code \Controls\WidgetZone.cs

  3. Find and Replace every  “Blog.CurrentInstance” string in the above mentioned files with the “Blog.PrimaryBlog” string 
  4. Repeat the same in all your “widget.cs”  “edit.cs” files in the “BlogEngine .NET /widget”  folder
    Replace “Blog.CurrentInstance. Cache” with the “Blog.PrimaryBlog.Cache
  5. Make the following changes in you “Global.asax.cs” file

     private static object _item = null;                   // added

      public static void Initialize(HttpContext context){

                if (_initializedAlready) {
                  
                    return;
                }
 
                lock (_SyncRoot){
                    if (_initializedAlready){
                        if(Blog.CurrentInstance.IsPrimary)    // added
                            return;
                      
                    }
                    _item = context.Items["app"];             // added
                    if(_item==null)
                       WidgetZone.PreloadWidgetsAsync(ZONENAME);
                    Utils.LoadExtensions();
 
                    Init_BundleTable();
 
                    _initializedAlready = true;
                }
            }
 

 

Then build your project to test the changes described. Everything should work fine now.

This workaround will give you a single WidgetZone rendering for all your blogs, both the primary one and all the subsequent ones, you’d wish to create them later.
 

It might not be the best solution, but at least it works smoothly, also when changing the UI culture /language.

Go ahead and good luck!

Tags:

The resource object with key '<key>' was not found.

by pinkbegemot 2. April 2013 15:22

One might run into this error after publishing a Web Application to IIS (7). This message actually means that ASP.NET simply can’t find the resource files, though the message text is somehow misleading.  There are comments on the Net, stating that simple copying the resource files to the appropriate folder solves the issue, but it doesn't. This might happen when you manually configure your deployed application to run in a Virtual Directory on IIS.

 SYMPTOMS

When you develop a web app in Visual Studio 2010 as a Web Project and debug it using local IIS, things work, as they should (hopefully). If you choose to use local IIS  7 and  run your application in a sub-folder of a main application (site) the Visual Studio’s function “Create Virtual Directory” will in fact create a sub-application on your IIS 7 and not a Virtual Directory. And your resource files will be found and used correctly.

 

But when you publish your application to the “WWWROOT” (or any other folder) you might come across a somewhat mysterious error message  “The resource object with key '<some key>' was not found”

 
RESOLUTION

  1. Make sure the required resource files are located in the “App_GlobalResources” folder of your application (can be the “App_LocalResources” as well)
  2. Make sure that the resource key in question is actually present in the resource files
  3. (and the winner is!) Make sure your application is configured as an Application  on IIS and not just as Virtual Directory

Parental Alienation, continued. Beware of the fifth column!

by pinkbegemot 17. December 2012 16:51

Hatred is not an emotion that comes naturally to a child. It has to be taught…

A child not suffering from Parental Alienation will readily forgive even an abusive parent, given a supportive environment. The absolute rejection of a parent is not indicative of child abuse.

 

If you are a targeted parent in a Parental Alienation drama and your child rejects you unjustly, you should be very careful in instructing your own family members and friends on how to behave wisely before they act at all.

Parental Alienation (PA) has numerous signs, chief of which begins with a question: “Why should children who were initially close to both parents suddenly seek to reject one of them?”. In short: Parental Alienation IS child abuse and emotional abuse.
It is known, that children who have been alienated (brainwashed) often express the same hostility as the custodial parent:

  •     they identify with and imitate the alienator;
  •     they do not wish to visit or spend time with the absent and alienated parent;
  •     the child’s views of rejecting the absent parent are virtually identical with the programming of the custodial parent;
  •     such children feel themselves to be powerful due to their alliance with the controlling and powerful alienator;
  •     they are not frightened (albeit they claim to be) by the absent parent or the court;
  •     the children have no valid reasons for rejecting the alienated parent, but will often manufacture these reasons or exaggerate events  
  •     they can see nothing positive or good about the absent parent and even the absent parent’s family
  •     they appear not to feel any sense of guilt about the way they treat the absent parent;
  •     they appear to be ‘normal’, yet appear also no longer to have a mind of their own being totally obsessed with the custodial parent and his implacable hostility towards the absent parent and frequently his/her extended family. These reactions are both pathological and unfair towards the targeted parent

There are many good articles and sites on Parental Alienation and I don’t intend to repeat here what already is written about either conscious actions or subconscious motifs of the alienating parents. What is rather poorly illuminated, but is very important to be aware of are the contributions from so-called surrogate alienators.  Surrogate alienators can be close family members, uncles, aunts, cousins etc and particularly friends. By supporting the alienator when it becomes clear to them just what is going on they are in fact supporting alienation. But the trouble is - they might not be aware of it!

I have a message to the alienated (targeted) parents, based on my own experience.  The tendency among the surrogate alienators (SA) is that they would try to maintain contact with your child, who is being alienated from you.  Many of them would do it without telling you anything. Some of them would tell you (when confronted), that they have a plan – and you would be inclined to believe it. Well, don’t! Just because the SAs do not have necessary insight in Parental Alienation dynamics, they think, they know better, but often they do more harm to your case than good. One must remember at all times, that alienators are often very skilled in manipulating not only the children, but everybody else in believing, that it is the child’s own wish to reject you. And the sad truth is that even members of your own family or your once close friends will soon start to believe it – even if they don’t admit it to you.
Some of them would feel like they must do something for the child (as they claim), but essentially those spontaneous actions directly or indirectly support the alienation. How come?

Well, firstly I can assure you, that almost every SA will try to avoid touching the very hot “Why?” topic while in contact with your child.  We all want to be good at least in our own eyes, and your sister or your friend is no exception. Therefore watch out, if and when they approach your brainwashed child with suggestions to spend time together. For everybody (or almost everybody) around  you such an action would look like a natural or even noble attempt to maintain close bonds with the child. Yes, for everybody, BUT the child herself.  
And this is very important to understand: children read their intentions differently.  For them the message is: “I support you, wright or wrong, it’s OK to be unfair”.  Alienated children feel great power after delivering programmed lies about the targeted parent. They know that they can get away with this.  They get an intoxicating feeling of control, it is THEM who decide. What they also learn all too well during the alienation is the remarkable ability to come up with the expected answers. They become very skilled in figuring out what reaction is anticipated of them and deliver it without any delay or hesitation. Along with alienators SAs thus teach them that moral and truth are just a casualty. Here are examples of such messaging:

  1. One of my own family members (a SA in this case), for instance, was happy to announce, that  just after a short stay with her the child allegedly changed her mind and expressed a wish to see the “guilty” alienated mother (me).  What this family member didn’t consider at all, was the simple fact, that the child just delivered an anticipated answer at the right time to cut an unpleasant interview short. And thus the child was in control once again!
  2. Another family member met my child on his own initiative, yielding to the child’s demand: mother was not to be involved! This family member even came up with a quite substantial gift for the child, thinking little of the message behind such a gesture. It can only be perceived as a reward (or even a bribe) by the child.
  3. One of my former female friends claims to keep in touch with my child and obviously is quite content to mention this once in a while. She also claims that she has a plan. The trouble is that the alienated child doesn’t know anything about such a plan. The child only sees what it wants to see – her mother’s own friend is amicable and tolerant towards the alienator (father, custodial parent) And what does such a friendly SA do? She asks the child straight: “Are you going to contact your mother soon?”  Well, one does not have to be a psychiatrist to figure out the child’s answer. Indeed, the child says “yes, I am”. And then what?  Nothing, right. It just goes on and on – polite lies. Nobody demands actions or confrontation. Why would the child want to initiate it?

Now, what is common in these episodes?

  1. All SAs  employ the same erroneous approach (which is the easiest path to take): they keep silent about the origin and nature of the alienation; at best they merely listen to the brainwashed child without even attempting to question fairness of such juvenile justice.  And the indoctrinated kid is all too ready to deliver a convenient for the moment answer or even impose a demand.
  2. They all give an alienated child something (a talk, a gift, a trip) without asking for anything in return.  Anything, that could lead a child to take a step away from the path lain by the alienator.


I am sure your friends and family members mean well, but they often tend to take children’s words at face value. Many of them believe that children will grow up and understand themselves. But this is not the case with severe PA.  Unfortunately, the psychological and emotional damage to kids is permanent and irreversible.

So, what is it those good Samaritans do not realize?  Essentially, they are all being passive and thus transferring control back to the smart (and now empowered) child.  But they should know better than this. In fact, all kids desperately need to know that the adults are in control. It's never too late to step up and take the reigns. And who has control in reality? The custodial parent, the alienator, of course. So, they are just back to square one, supporting the alienation.

Just my point. Unfortunately...

Useful links:

General info on PA

In-depth psychological view of PA 

P.S.  "Unconditional love is sincere and honest. It looks at the best of a person and encourages that individual to step forth. Then, it stands back, allowing that individual to choose for him or herself. There simply is no room for smallness or self-centeredness with unconditional love"

The Myths of Unconditional Love


Change language