Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Razor Pages #494

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

Razor Pages #494

NTaylorMullen opened this issue May 10, 2014 · 66 comments

Comments

@NTaylorMullen
Copy link
Contributor

NTaylorMullen 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 modified the milestones: 6.0.0-rc1, Backlog Sep 22, 2014
@yishaigalatzer yishaigalatzer modified the milestones: Backlog, 6.0.0-beta3 Jan 13, 2015
@DamianEdwards DamianEdwards modified the milestones: 1.1.0, Backlog Jul 13, 2016
@sirus-codes
Copy link

@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
Copy link

@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

@iamzm
Copy link

iamzm 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
Copy link

Why would it be less secure?

@Eilon
Copy link
Member

Eilon 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 [email protected] 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!

@sirus-codes
Copy link

@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

@sirus-codes
Copy link

@Eilon

@DamianEdwards
Copy link
Member

@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.

@sirus-codes
Copy link

@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
Copy link
Member

rynowak 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
Copy link

iamzm 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
Copy link

iamzm commented May 23, 2017

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

@iamzm
Copy link

iamzm commented May 23, 2017

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

@mikebrind
Copy link

@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
Copy link

iamzm 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
Copy link

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
Copy link

iamzm commented May 23, 2017

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

@RickStrahl
Copy link

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
Copy link

iamzm commented May 27, 2017

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

@rynowak
Copy link
Member

rynowak 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
Copy link
Member

rynowak 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.
Projects
None yet
Development

No branches or pull requests