Giter Site home page Giter Site logo

Comments (6)

tidyui avatar tidyui commented on August 22, 2024

Hi there! Which version of Piranha are you using and are you using the new startup or the old (advanced) setup?

from piranha.core.docs.

 avatar commented on August 22, 2024

I'm using 8.x and the assembly way of startup Code.

from piranha.core.docs.

tidyui avatar tidyui commented on August 22, 2024

We will add a documentation section about this.

from piranha.core.docs.

tidyui avatar tidyui commented on August 22, 2024

But as a preview.. If your web is built from the templates, you should add your own PageModel instead of using SinglePageModel<MyPage>. Like so

MyPage.cshtml

@page "~/myroute"
@model MyPageModel

MyPage.cshtml.cs

using Microsoft.AspNetCore.Authorization;
using Piranha;
using Piranha.AspNetCore.Models;
using Piranha.AspNetCore.Services;

[Authorize(Policy = "MyPolicyName")]
public class MyPageModel : SinglePageModel<MyPage>
{
    public MyPageModel(IApi api, IModelLoader loader) : base(api, loader) { }
}

This way you can use the AuthorizeAttribute to specify exactly who should have access to the page. It is not possible to reuse "views" with authorization attributes in the way you can with MVC as in MVC the controller action is called first and decides what view to use. In Razor Pages the "view" is called first and then tells which model to use.

Best regards

from piranha.core.docs.

 avatar commented on August 22, 2024

Oh @tidyui, thank you so much! You won't believe it.
I missed the '~' in the 'page' route. :-/ Sorry for wasting your time - but a section in the docs would be nice.

from piranha.core.docs.

tidyui avatar tidyui commented on August 22, 2024

We have new features for this is 8.1, check out the docs section for this!

from piranha.core.docs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.