我正在为我的网站使用MatBlazor,并且我已经使用这个伟大的博客:服务器端Blazor中的Google认证实现了谷歌身份验证
我希望在我的MatAppBar中有一个登录按钮(MatAppBar)。
原始代码有一个链接:<a class="ml-md-auto btn btn-primary" href="/Login" target="_top">Login</a>。
这个链接有效。我被重定向到我的OnGetAsync of my LoginModel。但它不符合我的UI风格。
这个按钮会转到正确的页面,但是我的OnGetAsync of my LoginModel不会被触发,只显示默认的Sorry, there's nothing at this address.。
<MatButton Class="mat" Outlined="true" Icon="Google" Label="Inloggen" Link="/Login"></MatButton>
我想我需要调整我的路线,但找不到办法。
更新
我的Login.cshtml.cs:
[AllowAnonymous]
public class LoginModel : PageModel
{
public IActionResult OnGetAsync(string returnUrl = null)
{
string provider = "Google";
// Request a redirect to the external login provider.
var authenticationProperties = new AuthenticationProperties
{
RedirectUri = Url.Page("./Login",
pageHandler: "Callback",
values: new { returnUrl }),
};
return new ChallengeResult(provider, authenticationProperties);
}
}我的Startup.cs:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseCookiePolicy();
app.UseAuthentication();
app.UseAuthorization();
app.UseEmbeddedBlazorContent(typeof(MatBlazor.BaseMatComponent).Assembly);
app.UseEndpoints(endpoints =>
{
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
}发布于 2020-04-11 23:27:48
我有一个非常类似的问题,我使用了上面列出的导航管理器选项,但是必须将ForceLoad参数传递为"true“。
void LoginClick()
{
navigationManager.NavigateTo("/login",true);
}发布于 2019-11-28 07:11:44
使用完整的URL
<MatButton Class="mat" Outlined="true" Icon="Google" Label="Inloggen"
Link="BaseUrl/Login"></MatButton>或者使用导航管理器导航该页面。
@inject NavigationManager navigationmanager
<MatButton Class="mat" Outlined="true" Icon="Google" Label="Inloggen" Onclick="@(()=>)"></MatButton>
code{
void clic()
{
navigationmanager.Navigateto("/Login")
}
}https://stackoverflow.com/questions/59067712
复制相似问题