我有一个带有GET和POST的创建操作的基本控制器。 GET工作正常并呈现页面,但是,POST总是将我重定向回登录页面,我的数据不会保存。我正在使用表单身份验证,但我还没有在任何控制器操作上使用[Authorize]属性。一切都在我的机器上本地工作正常,但当我发布到服务器时,这个错误开始发生。这是我的创建方法的代码:
[HttpGet]
public ActionResult Create()
{
var employee = new EmployeeViewModel();
return View(employee);
}
[HttpPost]
public ActionResult Create(EmployeeViewModel viewModel)
{
var dataModel = viewModel.TransformToDataModel();
allEmployees.Add(dataModel);
ViewData["SuccessMessage"] = string.Format("{0} successfully added to the system", viewModel.Name);
return View("Success");
}
我正在使用默认的AspNetSql Membership / RoleProvider / ProfileProvider,并使用IIS 7.0在GoDaddy上托管。以下是我的web.config文件的主要部分:
<authentication mode="Forms">
<forms
name="formCookie" protection="None" enableCrossAppRedirects="false" requireSSL="false"
loginUrl="~/Account/LogOn" timeout="2880" defaultUrl="~/Home/Index" path="/" />
</authentication>
<authorization>
<deny users="?"/>
<allow users="*" />
</authorization>
<identity impersonate="true"/>
如果有人之前遇到此错误或知道发生了什么,这将是非常有帮助的。谢谢!
答案 0 :(得分:1)
在ASP.NET MVC中,处理授权的首选方法是使用[Authorize]
属性。应删除web.config中的<authorization>
部分。