Asp.net mvc 4 ASP.net MVC返回表单上的Authorize属性(不带表单标记)

Asp.net mvc 4 ASP.net MVC返回表单上的Authorize属性(不带表单标记),asp.net-mvc-4,authorize-attribute,Asp.net Mvc 4,Authorize Attribute,在我在productcontroller的管理区域的创建操作中添加了Authorize属性之前,我的视图工作正常 [Authorize] public ActionResult Create() { ViewBag.Action = "Create"; VewBag.Category = new SelectList(this.categoryCoreModel.Categories, "CategoriaKy", "CategoriaDescIT"); ViewBag.SubCategory

在我在productcontroller的管理区域的创建操作中添加了Authorize属性之前,我的视图工作正常

[Authorize]
public ActionResult Create()
{
ViewBag.Action = "Create";
VewBag.Category = new SelectList(this.categoryCoreModel.Categories, "CategoriaKy", "CategoriaDescIT");
ViewBag.SubCategory = new SelectList(this.subCategoryCoreModel.SubCategories, "CategoriaSubKy", "CategoriaSubDescIT");
return this.View("Create", new ProductEditModel ());
}
在我看来

<div class="form">
    @using (Html.BeginForm((string)ViewBag.Action, "Product", FormMethod.Post, new { Model, enctype = "multipart/form-data" }))
    {
         ...............
         .............
 }

@使用(Html.BeginForm((string)ViewBag.Action,“Product”,FormMethod.Post,new{Model,enctype=“multipart/formdata”}))
{
...............
.............
}
我的问题是,当我点击Save按钮时,它会重定向到另一个不存在的URL,如Admin/Home。表单标签也丢失了。我错过了什么

编辑: 登录成功后,loginpartial视图呈现的表单似乎会弄乱我的产品表单

  @(Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm" })) {
            @Html.AntiForgeryToken()
            <a href="javascript:document.getElementById('logoutForm').submit()">Log off</a>
        }
@(Html.BeginForm(“注销”、“帐户”、FormMethod.Post、新的{id=“logoutForm”})){
@Html.AntiForgeryToken()
}

任何想法或反馈都非常好

我希望看到[Authorize(Roles=“SomeRoleName”)],这样您的授权可以证明用户拥有该角色,因为您没有指定角色(并且您可能没有实际登录),它会将您重定向到角色提供商指定的位置,即在loginUrl中

您是否像这样使用SimpleRoleProvider

<authentication mode="Forms">
  <forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
<roleManager enabled="true" defaultProvider="SimpleRoleProvider">
  <providers>
    <clear />
    <add name="SimpleRoleProvider" type="Models.SimpleRoleProvider, Models, Version=1.0.0.0, Culture=neutral" />
  </providers>
</roleManager>

如果是,则HttpContext.User.Identity和/或HttpContext.User.IsInRole不会返回[Authorize()]所期望的结果。我建议您查看“登录”部分,确保您将用户设置为已登录,并且他/她具有授权锁定的角色


希望这有帮助

我根本没有使用角色提供程序。我有用户匿名和身份验证。当我打开/Admin/Product/Create时,按预期重定向到Account/Login。成功登录后,它将重定向回/Admin/Product/Create。看起来不错。但当我使用“保存”按钮发回邮件时,它无法正常工作。因为我的页面没有表单标签,所以它重定向到了其他地方。您是否使用[httpget]和[httppost]属性以及不同的签名来分离方法,以便路由知道将httppost放在哪里?您可能需要提供不同的签名,并使用[httppost]装饰帖子,然后在属性中设置断点,以便您可以证明路由正在将您发送到正确的位置是的,我已经设置了[httppost]属性。但是视图在添加Authorize属性后不显示任何表单标记。它在没有授权的情况下运行良好