つばろぐ

主に C#, .NET, Azure の備忘録です。たまに日記。

PHPカンファレンス福岡2019の公式サイトがオープンしました! #phpconfuk

カンファレンスの準備は着々と進んでいます。
PHPカンファレンス福岡2019の公式サイトがオープンしました。ロゴもお披露目です。

phpcon.fukuoka.jp

公式サイトには多くのスポンサーやスタッフが掲載されており、カンファレンスに関わっている人が多いということを実感できます。

また、カンファレンス本編および懇親会の参加募集も開始しました。
それぞれ以下のリンクからお申し込みください。

eventon.jp

eventon.jp

さぁ、次のタスクは 登壇者の選考会 だ!!

PHPカンファレンス福岡2019のスピーカー募集が始まりました! #phpconfuk

先日、実行委員長やるよーとブログを書いたPHPカンファレンス福岡2019ですが、昨日(2/21)からスピーカー募集(Call for Speaker)が始まりました!
募集締切は 3月20日 です。

phpcon.fukuoka.jp

tsubalog.hatenablog.com

PHPカンファレンス」と言ってもテーマがPHPである必要はなく、

  • とにかくディープなPHPの話がしたい!
  • PHP初心者向けに丁寧な解説をしてみたい!
  • Web開発やシステム開発での体験談を話したい!
  • PHPじゃないけどどうしても伝えたい話がある!

こんな感じなので、話したいことがあるという方はどんどん申し込んでもらいたいと思います。

応募内容は締切後、カンファレンススタッフによる採択会議を経て、採択に至ります。

ASP.NET Core Razor Pagesにおける単一ページのルーティング

ASP.NET Core Razor Pagesでのルーティング設定につまづいたので手順を残しておきます。
ASP.NET Core MVCをよく使うため、単純に慣れの問題。

docs.microsoft.com

RazorPagesRouteSample
|--Areas
| |--Identity
| | |--Data
| | | |--RazorPagesRouteSampleIdentityDbContext.cs
| | |--IdentityHostingStartup.cs
| | |--Pages
| | | |--Account
| | | | |--Login.cshtml
| | | | |--Login.cshtml.cs
| | | |--_ValidationScriptsPartial.cshtml
| | | |--_ViewStart.cshtml
|--Pages
| |--_ViewImports.cshtml
| |--_ViewStart.cshtml
| |--Error.cshtml
| |--Error.cshtml.cs
| |--Index.cshtml
| |--Index.cshtml.cs
| |--Privacy.cshtml
| |--Privacy.cshtml.cs
| |--Shared
| | |--_CookieConsentPartial.cshtml
| | |--_Layout.cshtml
| | |--_LoginPartial.cshtml
| | |--_ValidationScriptsPartial.cshtml
| |--YourVoice.cshtml
| |--YourVoice.cshtml.cs
|--Program.cs
|--RazorPagesRouteSample.csproj
|--Startup.cs

上記のディレクトリ構成の場合を例にする。

ページを別名でアクセス可能にするルーティング

例: Pages/Privacy.cshtml へのアクセスを /SitePrivacy で可能にする。

Startup.cs

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc()
        .AddRazorPagesOptions(options =>
            {
                options.Conventions.AddPageRoute("/Privacy", "SitePrivacy/");
            })
        .SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}

ページを別名でアクセス可能にするルーティング(パラメーター付き)

例: Pages/YourVoice.cshtml へのアクセスを /Voice/{text?} で可能にする。

Startup.cs

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc()
        .AddRazorPagesOptions(options =>
            {
                options.Conventions.AddPageRoute("/YourVoice", "Voice/{text?}");
            })
        .SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}

YourVoice.cshtml

@page "{text?}" //受けるパラメーターを定義

YourVoice.cs

public class YourVoiceModel : PageModel
{
    public void OnGet(string text = null) //パラメーターを引数で受ける
    {
    }
}

エリア内のページへのルーティング

例: Identity エリアにあるログインページへのルーティング

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc()
        .AddRazorPagesOptions(options =>
            {
                options.Conventions.AddAreaPageRoute("Identity", "/Account/Login", "Login/");
            })
        .SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}

なお options.Conventions.AddPageRoute("/Identity/Account/Login", "Login/"); では正しいルーティング設定とならない。