Best way to conditionally render HTML content if user is an admin in ASP.NET Core 3.1 MVC - asp.net-core-3.1

I am developing an ASP.NET Core 3.1 MVC application and I want to conditionally render HTML based on the currently logged-in user's role. My current approach is to use a ViewComponent that will either render the links or not render the links based on the user's defined role. For example, if the user is authorized (based on his/her role) for the controller actions that those links perform, the ViewComponent will render the links. If the user is not authorized, the ViewComponent will will hide the links altogether. Does anyone have a better approach? (The action methods in the controllers are appropriated decorated with the Authorize annotation; e.g., [Authorize(Roles = "Admin")].)

Related

Recently viewed pages in AEM

I am trying to implement a feature where user can see what all last 5 pages he visited during current session. This is for anonymous user as site does not have any login/registration module available.
I can think of creating a data structure in user current session and add page names there and as user browse page from page, add page name in that collection using either request post processor or in a servlet. This servlet can be called using a HTL component passing json data to UI. Challenge here would be to maintain a consistent user session across journey.
OR
I can use some third party tool say Adobe analytics or Target etc for same?
Any suggestion?

Dynamically linking to a Facebook Company Page

Our database has an entry for our companies' Facebook and Twitter pages. With Twitter, it's possible to create dynamic links based solely on the company's Twitter handler. For instance, if the company provides us with the Twitter handle acme, we can dynamically create a link to their Twitter page with <a href='http://www.twitter.com/#{company.twitter_name}'></a>.
In some instances, the same is true of Facebook. Coca Cola for instance has http://www.facebook.com/cocacola. Many other companies have a url that looks more like http://www.facebook.com/pages/acme/123456789. In the latter case, the numerical id at the end is necessary to reach the page. The URL http://www.facebook.com/pages/acme would not work.
My question is, is there a way to dynamically link to a Facebook company page with just their handle? Or do you always need to provide a full URL? I'm hoping Facebook has some magic back door for developers that I simply haven't happened upon yet. Thanks for your feedback, one way or the other!
A link in the form http(s)://facebook.com/profile.php?id={nummeric_id_here} always works, for pages as well as for user profiles.
It automatically redirects to the “real” address – to the username that the user or page might have set, or to an address in the form you mentioned (for pages that do not have enough likes yet to set their own user name).

How to force user to submit a form before allowing them access to the rest of the site?

What I have to accomplish is to collect some information from the users of the web system before letting them doing anything else on the site. These users are already registered and have roles assigned in asp membership/roles providers. I am able to redirect them to the form that I need them to submit right after they authenticate, however that wouldn't prevent them to navigate to other parts of the system without filling it out. My only thought so far is to insert a check if the user has filled the form in every action of the system and if they didn't - I would redirect them to the form, but that seems like a really horrible idea. What would be the best way implement that functionality for an asp.net mvc2 web app?
Have an Intercepting Filter on the web site that checks on every request to make sure the data is filled out. If it isn't then redirect them to the form.

Checking if user doesn't allow Canvas App in Facebook C# MVC

I am trying to track the number of users who did not allow my app during authorisation using the Facebook C# SDK and ASP.NET MVC.
By specifying the CanvasAuthorize attribute on my landing page, user will get redirected to
a url like this:
canvasurl/facebookredirect.axd?error_reason=user_denied&error=access_denied&error_description=The+user+denied+your+request.&state=eyJyIjoiaHR0cDovL2FwcHMuZmFjZWJvb2suY29tL25pdmVhdGVzdGVydCJ9
My question here is..how do i code my app in such a way that i can read the querystrings and track the number of times my app has been denied access?
By using the CanvasAuthorize attrib on your action there is also a parameter for CancelUrlPath, like so:
[CanvasAuthorize(Permissions="user_likes,email", CancelUrlPath="YOUR_PATH_HERE")]
This will allow you to set the path to an action that you can do all the tracking you like.
Hope this answers your question.
-Joey

Can I access Facebook API's without an api_key?

Is it possible to access Facebook APIs for logging in a user, or to allow a user to become a fan of a fan page through a third party site, without actually creating an app on facebook?
Why don't you create a fab page directly for users to become fans for that page? And as far as i know, you can not access facebook API without API key.
You can't access the API without creating an application and getting an API key. There are a small number of API queries that will work without the user having added an application or even interacted with it but they generally on retrieve very basic data.
There's certainly no programmable way of making a user a fan of a page without using a fan box widget or having them do it directly through the site. This is because the post_form_id value which Facebook uses for these kinds of interactions is only present on pages served from facebook.com and is never accessible to the developer. To allow otherwise would open up the system to all kinds of exploitation.
I've no idea what problem you're trying to solve anyway. Creating an application API key is no hardship (and it doesn't have to be an active application for session-less queries - just create an app and grab the keys) and the fan box widget can be styled with CSS, as long as you follow the basic rules that Facebook has set out.