Serenity: Public access

Created on 21 Feb 2017  路  9Comments  路  Source: serenity-is/Serenity

Hi guys, how can i give public access permissions to one of my pages. I mean, i have this pages/folders:

  • Project.Model.Entity1 (page1): Admin,User
  • Project.Model.Entity2 (page2): Admin
  • Project.Model.Entity3 (page3): User
  • Project.Model.Entity4 (page4): Public access (No auth required)

Page 4 -> Form panel as "@Serenity.Decorators.panel()"

I tried removing my entity4 row ReadPermissionAttribute. But i got this error:
"System.ArgumentOutOfRangeException: ServiceAuthorize attribute is created with source type of Entity4Row, but it has no ReadPermissionAttribute attribute(s)".
Then i tried '[ReadPermission("")]', but public still cant read data from my entity.

Any help is apreciated. Thanks in advance! :wink:

Most helpful comment

Remove ServiceAuthorize

All 9 comments

ReadPermission("*") means users including unauthenticated ones.

Hi @volkanceylan i made this changes on my Entity4Row:

[ReadPermission("*")]
[ModifyPermission("*")]

My Entity4Page has _[PageAuthorize(typeof(Entities.Entity4Row))]_

My Entity4Endpoint is:

using MyRow = Entities.Entity4Row;
[ConnectionKey(typeof(MyRow)), ServiceAuthorize(typeof(MyRow))]

But now when i try to place this URL on my browser:
http://[myIP]:[port]/Project/Model/Entity4/IdEntity4
Im linked to my LogIn page:
http://[myIP]:[port]/Project/Account/Login?ReturnUrl=%2fProject%2fModel%2fEntity4%2IdEntity4

What am I doing wrong? Thanks again sir!

So remove authorize from all

Ok @volkanceylan now i got this error:

Authorization.NotLoggedIn

Then i set my Entity4Endpoint from this:

[ConnectionKey(typeof(MyRow)), ServiceAuthorize(typeof(MyRow))]

To this:

[ConnectionKey(typeof(MyRow))]

And finally i can access to my Entity4 Form Panel as public user. But if i try to insert a new record or modify an existent Entity4Id i obtain this error again:

Authorization.NotLoggedIn

So I tried to change my Row for the second time like this:

[ModifyPermission("*")]
[UpdatePermission("*")]
[InsertPermission("*")]
[ReadPermission("*")]
[DeletePermission("*")]

But im still getting this error: Authorization.NotLoggedIn

The app check my Application_AuthenticateRequest and then in AuthorizationService it returns false here:

public bool IsLoggedIn
{
     get { return !string.IsNullOrEmpty(Username); }
}

What should i do now. I really appreciate your help and knowledge. Many thanks!

If you intentionally want to make public. You can safely remove these

[ModifyPermission("*")]
[UpdatePermission("*")]
[InsertPermission("*")]
[ReadPermission("*")]
[DeletePermission("*")]

Thanks for your answer @dfaruque . I removed these lines:

//[ModifyPermission("*")]
//[UpdatePermission("*")]
//[InsertPermission("*")]
//[ReadPermission("*")]
//[DeletePermission("*")]

Then i received this error:
_ServiceAuthorize attribute is created with source type of Entity4Row, but it has no InsertPermissionAttribute OR ModifyPermissionAttribute OR ReadPermissionAttribute attribute(s)_

So i kept this line:
[ReadPermission("*")]

My Entity4 Form Panel its ok again, and i can read any Entity4Id used at the end of my URL (...Entity4/Id). But if i try to modify any content i still receive this error:
{Error: {Code: "NotLoggedIn", Message: "_Authorization.NotLoggedIn_"}}

I'm trying to modify these Entity4Id data as public. As any visitor, not like user logged into my app.
Thanks again!

Remove ServiceAuthorize

@alanlopcu I think you can add a tutorial about public pages and endpoints into the wiki.

After removing ServiceAuthorize attribute from class, I have removed Authorize attribute from create, update, delete method too to work done.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ga5tan picture ga5tan  路  3Comments

AmuthaKondusamy picture AmuthaKondusamy  路  3Comments

john20xdoe picture john20xdoe  路  3Comments

chintankukadiya18 picture chintankukadiya18  路  3Comments

Amitloh picture Amitloh  路  3Comments