umbraco 7.1注销(razor语法c#)

本文关键字:语法 razor 注销 umbraco | 更新日期: 2023-09-27 18:18:35

我有一个umbraco 7.1网站,我使用它自己的会员系统。我可以很容易地登录,看到我的状态,甚至更改密码,但没有注销命令,我不知道我应该使用什么方法为umbraco 7注销当前用户。我知道我可以清除cookie和成员身份,但它总是给出一个运行时错误。帮帮我!: D

umbraco 7.1注销(razor语法c#)

在后台(Admin),您可以添加一个新的局部视图并选择登录状态模板,您将获得以下代码。

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@using System.Web.Mvc.Html
@using ClientDependency.Core.Mvc
@using Umbraco.Web
@using Umbraco.Web.Models
@using Umbraco.Web.Controllers
@{
    var loginStatusModel = Members.GetCurrentLoginStatus();
    Html.EnableClientValidation();
    Html.EnableUnobtrusiveJavaScript();
    Html.RequiresJs("/umbraco_client/ui/jquery.js");
    Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.min.js");
    Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.unobtrusive.min.js");
    var logoutModel = new PostRedirectModel();

    //Here you can specify a redirect URL for after logging out, by default umbraco will simply
    //redirect to the current page. Example to redirect to the home page:
    //logoutModel.RedirectUrl = "/"; 
}   // NOTE: This RenderJsHere code should be put on your main template page where the rest   of your script tags are placed
@Html.RenderJsHere()
@if (loginStatusModel.IsLoggedIn)
{
    <p>You are currently logged in as @loginStatusModel.Name</p>
   using (Html.BeginUmbracoForm<UmbLoginStatusController>("HandleLogout"))
   {
        <fieldset>
            <legend>Logout</legend>
            <button>Logout</button>
        </fieldset>
       @Html.HiddenFor(m => logoutModel.RedirectUrl)
   }
}

FormsAuthentication.SignOut();