Dailycode.info

Short solution for short problems

AngularJS and .Net WEB.API: 405 (Method Not Allowed) for PUT and DELETE

I was having some problems with put and deletes. When I ran the code on the localhost, no problem, but after installing on the servers, delete calls were giving CORS errors. I tried to figure out what was going on, but I lost some time. First I rewrote the methods to POST methods, this worked. But when a new occasion came to look for a better solution I found it here.

The thing is that DELETE and PUT are sending a OPTION request first to the API on the server. If this method is not there, then it will not work. The error message will not really point you into the right direction. 

But instead of adding the OPTION methods foreach DELETE or PUT you could also disable WebDAV in IIS. That really does the trick. No code changes needed, just a simple configuration.

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true">
    <remove name="WebDAVModule"/>
  </modules>
  <handlers>
    <remove name="WebDAV" />
  </handlers>
</system.webServer>

And thatis it.

No more of these now:



Message count in MSQUEUE

An easy powershell comment can help to get more info about a messagequeue.

This get more info on all the queue's you have defined:

# Get all message queues
Get-MsmqQueue;

The next command gives youa table overview of all queue's and their item count:

# Get all the private message queues.
# Display only the QueueName and MessageCount for each queue.
Get-MsmqQueue -QueueType Private | Format-Table -Property QueueName,MessageCount;


Source Link

You could off also take a look in the queue browser:



EF: Oracle.ManagedDataAccess Specified Cast is not valid on decimal

Error: Specified cast is not valid. 

CorrId: GetClientAcceptances 

Stack: at Oracle.ManagedDataAccess.Client.OracleDataReader.GetDecimal(Int32 i) 

at Oracle.ManagedDataAccess.Client.OracleDataReader.GetValue(Int32 i)

Got this error while working with EF 6 and Oracle DB. Using the Oracle.ManagedDataAccess package. (Version about packages below)


The reason was that in Oracle the number type was set on a column and no precision specified. We had some old data that had some values with a very large precision, and when EF tries to map it to a decimal, there was a specified cast exception. So I rounded all the records in the DB to precision 2, because that was enough for this application and the problem was solved. Some helper query for this:


select RISKFACTOR from MYTABLE where RISKFACTOR - trunc(RISKFACTOR,3) <> 0;
update MYTABLE set RISKFACTOR = ROUND(RISKFACTOR,2) where RISKFACTOR - trunc(RISKFACTOR,3) <> 0;


  <package id="Oracle.ManagedDataAccess" version="12.1.24160719" targetFramework="net461" />

  <package id="Oracle.ManagedDataAccess.EntityFramework" version="12.1.2400" targetFramework="net461" />



Passing objects in methods by ref or not....

public void Foo(Image image)
{
    // This change won't be seen by the caller: it's changing the value
    // of the parameter.
    image = Image.FromStream(...);
}

public void Foo(ref Image image)
{
    // This change *will* be seen by the caller: it's changing the value
    // of the parameter, but we're using pass by reference
    image = Image.FromStream(...);
}

public void Foo(Image image)
{
    // This change *will* be seen by the caller: it's changing the data
    // within the object that the parameter value refers to.
    image.RotateFlip(...);
}
Source: Stackoverflow

AngularJS: How to build your own translation service PART 2

Ruben continued on the translation service blog resulting in a language picker that translates your entire site. You can find the post here:

How to – Build your own Angular translation service – Part 2 

Looking forward to PART 3 where Ruben B from Spikes will show how to implement json files to handle the translations, this way you can get the text from "any" data source.


AngularJS: How to build your own translation service

Ruben Biesemans started a post on how to implement your own translation service. Why you might ask. For him mainly educational purpose, for us, it's an opportunity to have a guideline on how to build your own translation service. Because many might find the existing solutions to complex or just not flexible enough. Here's a link to the part 1 and looking forward to the next part.

How to – Build your own Angular translation service – Part 1

spikesapps.wordpress.com

Intro This will be a first in a series of posts in which I will build a translation service for Angular from the ground up. I want to point out up front that I know there are multiple angular trans… read more here


EF : Oracle and EF Code First “Invalid column name 'Discriminator'”

I got this little nasty error when working with EF6 and Oracle DB: ORA-00904: "Extent1"."Discriminator"

Didn't look that far, based on this post I found my answer!

I had a class: Clients, added to the context. 

That worked fine. 

Now I created a second class, ClientExtra not added to the context but this inherited from the Client object.

(Why you might ask, I used this class in a database query, it had some extra properties and no table reflecting in the already exiting DB)

After doing this, EF gave me the above error.

It could look like this:

public class Client
{
    public int Id { get; set; }

    public string Name { get; set; }
}

public class ClientExtra : Client
{
    public string City { get; set; }
}

Solution

First create a common base class, ClientBase, add all properties from the client object. Do not add the ClientBase to the context. Then you have Client en ClientExtra inherit from this base class without problems.

public class BaseClient
{
    public int Id { get; set; }

    public string Name { get; set; }
}

//In the context
public class Client : BaseClient
{ }

//Not in the context
public class ClientExtra : BaseClient
{
    public string City { get; set; }
}



EF : Guid.ToString() in LINQ Where Statement

It's important to understand LINQ order in order to write correct LINQ statements.

Recently I bumped into this one:

public CRM_OPPORTUNITYCLOSED GetAcceptanceClosed(Guid guid)
{
 return Context.CRM_OPPORTUNITYCLOSEDSet.FirstOrDefault(o => o.OPPORTUNITY_ID == guid.ToString());
}

When this was run to the Oracle DB, I got this error:

ORA-00932: inconsistente gegevenstypen: - verwacht, NCLOB gekregen

or in English:

ORA-00932: inconsistent datatypes: expected - got CLOB

So what happened? You would expect that the ToString() was called before EF would go the the DB? In this case NO. It passes the Guid value to the DB and you get the error above.

So do your to string convert before you use the query. 

public CRM_OPPORTUNITYCLOSED GetAcceptanceClosed(string guid)
{
 return Context.CRM_OPPORTUNITYCLOSEDSet.FirstOrDefault(o => o.OPPORTUNITY_ID == guid);
}



AngularJS: Authorize app

Ruben of Spikes provides a detailed implementation of using windows authentication to authorize Angular apps. In this case using the UI-router.

Spikes Apps

In my previous post I explained how to set up windows authentication in an Angular application.

In this post I will explain how to implement authorization in the application based on the authenticated user.

I’m starting this post with the code base of the previous post.

Extending the Web API

I’ll extend the API with a new model, AppUser, which will contain the user information that is necessary for Authorization in the application.

Next I will change the WinAuthController. I’m returning an instance of the AppUser object when the user is successfully authenticated.

Typically, you would want to load the information from a database or something. To keep things simple, I’m just returning the domain name and a fixed role.

Extending the Angular application

In the Angular application, I’m moving the AuthenticationService into a separate Angularmodule, which I’m calling ‘debiese.security’. I’ll also add an AuthorizationService

View original post