Skip to content
This repository has been archived by the owner. It is now read-only.

Razor Pages #494

Closed
NTaylorMullen opened this issue May 10, 2014 · 66 comments

Comments

@NTaylorMullen
Copy link
Member

commented May 10, 2014

We will support a simple model where a user can crate a CSHTML page that can handle requests but still use the primitives of MVC.

| 57 | 10153 | Reported By: Yishai Galatzer |

@JaneZhouQ JaneZhouQ added this to the Post Alpha milestone May 13, 2014

@kanchanm kanchanm modified the milestones: Alpha, Post Alpha May 14, 2014

@danroth27 danroth27 changed the title We will support Web Pages style pages, using WebFX as the underlying framework. Web Pages framework May 29, 2014

@danroth27 danroth27 modified the milestones: 1.0.0-beta1, 1.0.0-alpha2 May 29, 2014

@danroth27 danroth27 added the feature label May 29, 2014

@danroth27 danroth27 modified the milestones: 6.0.0-rc1, Backlog Sep 22, 2014

@danroth27 danroth27 added 0 - Backlog and removed 1 - Ready labels Sep 22, 2014

@danroth27 danroth27 removed the 0 - Backlog label Oct 30, 2014

@yishaigalatzer yishaigalatzer modified the milestones: Backlog, 6.0.0-beta3 Jan 13, 2015

@danroth27 danroth27 added enhancement and removed enhancement labels Jul 7, 2016

@DamianEdwards DamianEdwards modified the milestones: 1.1.0, Backlog Jul 13, 2016

@cyrusel

This comment has been minimized.

Copy link

commented Feb 25, 2017

@DamianEdwards
good luck, please make it simple as web pages is to encourage php guys to leave it and join asp.net core. thank you so much man.

@villanus

This comment has been minimized.

Copy link

commented Feb 25, 2017

@DamianEdwards as cyrusel pointed out it might be good to have a full beginner training path. For js, php, classic asp devs, who want to jump into core without mvc.

It would be nice if the training vision was to star on razorpages, then add more advanced and eventually learn MVC.

I see how this would be useful for both evangelists, and the comunnity.

Versus just having a different framework

@danroth27 danroth27 changed the title MVC View Pages Razor Pages Mar 3, 2017

@rynowak rynowak added this to Needs Design in Razor Pages 2.0.0-preview1 Apr 10, 2017

@rynowak rynowak added 3 - Done and removed 2 - Working labels Apr 27, 2017

@rynowak rynowak closed this Apr 27, 2017

@rynowak rynowak moved this from Design to Done in Razor Pages 2.0.0-preview1 Apr 27, 2017

@iamzm

This comment has been minimized.

Copy link

commented May 21, 2017

Will this not be less secure and also my concern is it will make page rendering slow ?? Can anyone help me

@villanus

This comment has been minimized.

Copy link

commented May 21, 2017

Why would it be less secure?

@Eilon

This comment has been minimized.

Copy link
Member

commented May 22, 2017

@iamzm the security is the same as the rest of ASP.NET Core. If you have any specific concerns, please let us know! If you think you've found a security bug, please contact secure@microsoft.com with a detailed bug report.

The performance in general should be roughly the same as ASP.NET Core MVC, because Razor Pages is built on ASP.NET Core MVC. If you have observed performance issues, please log a bug in this repo and we will investigate.

Thanks!

@cyrusel

This comment has been minimized.

Copy link

commented May 22, 2017

@eliton There is something wrong related to microsoft.dotnetcore.mvc.taghelpers! if you remove it from _viewstart and submit the form with Post method, request validation token won't be generated and you will get bad request (error 400). In fact either unti-forgery should not be relied on tagHelpers or there should be a way to disable unti-forgery.
thanks

@cyrusel

This comment has been minimized.

Copy link

commented May 22, 2017

@DamianEdwards

This comment has been minimized.

Copy link
Member

commented May 22, 2017

@cyrusel if you remove the Tag Helpers registration then the anti-forgery token will not be rendered with the form, hence the failure on POST as the page expects a token by default. You can disable anti-forgery but it's not recommended.

@cyrusel

This comment has been minimized.

Copy link

commented May 22, 2017

@DamianEdwards
First.. Thanks for your huge efforts and creating such amazing model.
How can I disable anti-forgery? bcuz I want to implement my custom code instead.
Also I think the way you design, it's mandatory to use tagHelpers otherwise we lose anti-forgery feature. Maybe somebody doesn't want to use tagHelpers!
Thanks again

@rynowak

This comment has been minimized.

Copy link
Member

commented May 22, 2017

            services.AddMvc().AddRazorPagesOptions(o =>
            {
                o.ConfigureFilter(new IgnoreAntiforgeryTokenAttribute());
            });

This will turn off autiforgery token validation for pages.

You can also still generate an antiforgery token the old fashioned way using @Html.AntiForgeryToken()

@iamzm

This comment has been minimized.

Copy link

commented May 23, 2017

@Eilon Thanks for making things clear. Regarding slowness i meant if we are going to write our business logic in Page itself .. Don't you think it can be improper pipeline ? Can you please explain a little

@iamzm

This comment has been minimized.

Copy link

commented May 23, 2017

@DamianEdwards What if i have to write non-CRUD method ?? Like you guys are suggesting On- ??

@iamzm

This comment has been minimized.

Copy link

commented May 23, 2017

@DamianEdwards What if i want to redirectto("www.facbook.com") ? any possible way here ?

@mikebrind

This comment has been minimized.

Copy link

commented May 23, 2017

@iamzm If you want to redirect to another site, you can use Response.Redirect or return an MVC RedirectResult:

public void OnPost()
{
    Response.Redirect("http://www.facebook.com");
}

or

public RedirectResult OnPost()
{
    return Redirect("http://www.facebook.com");
}

There is no reason for putting business logic inline. You place it in the page controller or in a separate layer which is called in the page controller. If you do put your business logic inline, your application is unlikely to experience any slowness in running. It may take longer to compile the page on first run, and it is likely to make it more difficult to maintain in the longer run if it's a true business app, and not just a simple blog.

You can structure your Razor Pages application in exactly the same way as an MVC application, except that you have one controller per view in Razor Pages instead of one controller per feature or business area in MVC. Most of the rest of Razor Pages is the same ASP.NET Core as MVC.

@iamzm

This comment has been minimized.

Copy link

commented May 23, 2017

Thanks @mikebrind what if i want to write non-crud action in Page ? Like instead of OnPost, OnGet, OnDelete .. Is it possible i can write my custom method like verifyemail ? So can i follow like

OnVerifyEmail ??

@mikebrind

This comment has been minimized.

Copy link

commented May 23, 2017

You can add any method to your page. This is how you might do it:

@{
    @functions{
        
        public void OnPost(string email)
        {
            if(VerifyEmail(email))
	    {
	         Response.Redirect("http://www.facebook.com");
	    }
        }

        public bool VerifyEmail(string email)
        {
            return Regex.IsMatch(email, @"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");
        }
    }
}
@iamzm

This comment has been minimized.

Copy link

commented May 23, 2017

@mikebrind Thanks for helping me out ! I had also same idea but wanted to be sure

@RickStrahl

This comment has been minimized.

Copy link

commented May 27, 2017

Is there any discussion anywhere about some mechanism to embed RazorPages without running a Web application? Essentially using razor as a stream/string templating engine inside of a another application that is not a Web app or even just a sub-system that doesn't know about a Web app?

@iamzm

This comment has been minimized.

Copy link

commented May 27, 2017

@RickStrahl Libraries are must i think to include to get RazorPages work even in another outside application

@rynowak

This comment has been minimized.

Copy link
Member

commented May 30, 2017

@RickStrahl

We have our own usage of Razor like this here. This is what powers the developer exception page and the like.

There's a sample using Razor + someof MVC to generate templated emails here.
https://github.com/aspnet/Entropy/tree/dev/samples/Mvc.RenderViewToString

If there's something in particular that we need to improve for this usage of Razor, please open issues.

@rynowak

This comment has been minimized.

Copy link
Member

commented May 30, 2017

Locking this ancient issue because we've implemented it!. If you have something to talk about please open a new issue instead of posting on this one, thanks!

@aspnet aspnet locked and limited conversation to collaborators May 30, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.