Base solution for your next web application
Open Closed

Public pages #7992


User avatar
0
digitalcontrol created

We would like to open some pages publicly depending on our business logic condition. So if some property is true particular pages will be publicly accessible. Is there a recommended way of implementing such functionality? We are aware of public portal but that is not what we need.


11 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    So if some property is true particular pages will be publicly accessible

    I don't know where your conditions come from? Settings?

    If the page is small, you can judge the business logic directly in the action. A more advanced approach is to use mvc filters or abp interceptors based on some attributes.

  • User Avatar
    0
    digitalcontrol created

    We were investigating more what are our options but did not find an appropriate solution yet. We have page where we are listing users posts, each post has details page where are some comments (simple ticketing system, similar to your support forum) and we want to open Post listing page as well as Post details page to visitors who are not logged in (same as your support forum page) where these visitors can see the content but can not post or comment before they log in. An additional feature is that we need this configurable which means that these pages will be publicly accessible only if we set it to public under settings (In DB, let's say tenant configuration).

  • User Avatar
    0
    maliming created
    Support Team

    I believe that abp's setting + permission system can meet your needs.

  • User Avatar
    0
    digitalcontrol created

    If you can provide some more details it would be good. Here is what we've done. The question is "Is this good approach or there is something more convenient?". Frontend:

    • in auth-route-guard.ts we removed if (!this._sessionService.user) - so we don't get redirected to login page
    • in routing modules we removed data: { permission: '...' } where we wanted to open routes
    • in app-navigation.service.ts we removed permissions for the items we want to be visible to public users
    • in topbar.component.ts in setCurrentLoginInformations method we check first if appSession.user exists and then based on result we display in topbar username or login button
    • we removed all UserLinkServiceProxy service calls since we don't use them in out app
    • and commented the part of the code related to notifications for now, but that won't be a problem because we will just update endpoints to return appropriate response based on is user logged in or not Backend:
    • in ProfileAppService in GetProfilePicture method we check first if AbpSession.UserId.HasValue and then load profile picture, otherwise just return new GetProfilePictureOutput(string.Empty);
    • For now we just set attribute AbpAllowAnonymous in some app services for testing purposes, but we will add custom attribute where we will filter private/public data based on is user logged in or not
  • User Avatar
    0
    digitalcontrol created

    Is there any help regarding this situation?

  • User Avatar
    0
    digitalcontrol created

    Hi, When we can expect some answer?

  • User Avatar
    0
    digitalcontrol created

    Are you still with us?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @digitalcontrol

    First of all, sorry for our late reply.

    It is a bit hassle to do this for a page under app module. It is better to create a second module similar to account module and place your pages in that module. Would that work for you ?

  • User Avatar
    0
    digitalcontrol created

    Hi @ismcagdas Unfortuanatlly that is not solution, we already tried that option but since we need that public/private switch configurable (depend which option is active) we need it under app module. Another reason would be that we want same routes(URLs) in both situations. Can you give us some guidlines for doing this under app module? For now we are trying but hitting wall by wall

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @digitalcontrol

    Thank you for clarification. That's normal becasue app module is not designed to work that way. Could you share what is the last problem you are having ?

    By the way, you can use AbpAllowAnonymous on the server side and switch logic using the value of AbpSession.UserId.HasValue .

  • User Avatar
    0
    ismcagdas created
    Support Team

    This issue is closed because it has not had recent activity for a long time.