Why Doesn't Include Have Any Effect

Why doesn't Include have any effect?

Using ste-fu approach it did not worked, but with a variation of it I was able to put it to work.

I guess Gert Arnold answered why it does not work, but since I got it working here is the code:

var sharePeople = Context.SharePeople.Include("Person");

return sharePeople.Where(s => s.Shares.Car.CarId == carId);

Why doesn't likely and unlikely macros have any effect on ARM assembly code?

As @rici said, your code is simple enough that it can be realized by conditional instructions. You can see a difference, e.g., if you call functions which are implemented in a different compilation unit:

#define likely(x)    __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)

// only forward declarations:
void foo();
void bar();

int main(char *argv[], int argc)
{
if (likely (argc == 2))
foo();
else
bar();
}

Changing likely to unlikely switches the order of the if and else branch, for ARM and x86: https://godbolt.org/z/UDzvf0. If this really makes a difference likely depends on the hardware you are running on, whether you call the function the first time (otherwise, the CPU-internal branch prediction likely has a higher influence than the order of the instructions), and probably many other things.

Why RequiredScope attribute doesn't have any effect?

What you need to do is to add and configure authorization in Startup.cs like, like this:

public void ConfigureServices(IServiceCollection services)
{
services.AddAuthorization(options =>
{

options.AddPolicy("ViewReports", policy =>
policy.RequireAuthenticatedUser()
.RequireRole("Finance")
.RequireRole("Management")
);
});

The policy says that the user must be authenticated and be in both roles. In this example RequireAuthenticatedUser() is optional.

Then you can use that policy like:

[Authorize(Policy = "ViewReports")]
public IActionResult ViewReports()
{
return View();
}

To get the role claim to work, you must define what the name of your role claim is in the token, by doing this:

services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters.NameClaimType = "name";
options.TokenValidationParameters.RoleClaimType = "role";
});

Otherwise the role might not be found, because OpenIDConnect and Microsoft have different opinion on what the claim should be called.

In the long run, using polices will gives you better and cleaner code, because if you need to change the scopes in the future, you need to update all controllers classes. With a policy , you change it in one place.

Also, according to this issue at GitHub, it says:

RequiredScopes just checks at the scp or
http://schemas.microsoft.com/identity/claims/scope claims.

This means that you might need to do some claims transformation (renaming) to get the RequiredScope to map to the scope claim in your access token.

Why setting null in the middle of std string doesn't have any effect

A std::string is not like a usual C string, and can contain embedded NUL characters without problems. However, if you do this you will notice the string is prematurely terminated if you use the .c_str() function to return a const char *.

How many other files does include affect aside from the one it's in?

The effect of #include is as if the referenced file's contents completely replace the #include statement itself.

Your Subclass class is derived from Baseclass. The subclass.h header file declares Subclass, therefore when compiling subclass.h, the definition of Baseclass must be available.

Except, and this is the key point, you do not exactly compile subclass.h. You are compiling RetroProject.cpp. This is what your compiler is actually compiling. Or, rather, begins compiling.

Your compiler starts compiling RetroProject.cpp, reading the file from its beginning to its end. Each time it encounters a #include, the referenced file's contents completely replace the #include statement, and the compiler then resumes reading and compiling the code, starting with the #included text. When it sees another #include, the process repeats.

So, if you have a #include "baseclass.h" in subclass.h, then the following happens. When your RetroProject.cpp #includes subclass.h, the contents of subclass.h replace the #include statement in RetroProject.cpp, then, the compiler resumes compiling, it sees another #include, and then it replaces that #include with the contents of baseclass.h.

The compiler then parses baseclass.h, which defines the BaseClass, and then it compiles the rest of subclass.h, which defines SubClass, and since BaseClass is already defined, there is no issue.

If you explicitly #include the baseclass.h file in retroproject.cpp, then the compiler first replaces that #include with the contents of baseclass.h, compiles it, defines the BaseClass, then the #include of the subclass.h file gets processed the same away, and, once again, everything that should be defined, is defined.

Why doesn't .htaccess have any effect?

You're on Debian, according to your tags. The default site, at least on Lenny in its default configuration of apache2, is defined in /etc/apache2/sites-available/000-default. This default has AllowOverride None in the section for the /var/www directory. So, that could be overriding your apache2.conf.

Of course, you would need to ensure that the site is enabled. If /etc/apache2/sites-enabled/000-default exists and is a symlink pointing to /etc/apache2/sites-available/000-default, then the site is enabled. The canonical way to enable such a site is, as root, a2ensite 000-default.

Finally, realize that if you have access to the main configuration, for performance reasons, you should configure your site using the main configuration (or the site configurations in /etc/apache2/sites-available) rather than in .htaccess. See http://httpd.apache.org/docs/2.2/howto/htaccess.html for further explanation.



Related Topics



Leave a reply



Submit