using System;
using System.Web.Mvc;
namespace WebApplication1.Controllers
{
public class SignInModel
{
public string Name { get; set; }
}
public class AccountController : Controller
{
public ActionResult UnAuthorize(string ReturnUrl)
{
return Redirect("/Account/SignIn?ReturnUrl=" + ReturnUrl);
}
[HttpGet]
public ActionResult SignIn(string returnUrl)
{
ViewBag.ReturnUrl = returnUrl;
return View();
}
[HttpPost]
public ActionResult SignIn(SignInModel model, string returnUrl)
{
try
{
return Redirect(returnUrl);
}
catch (Exception ex)
{
throw;
}
}
}
}
SignIn view
@model WebApplication1.Controllers.SignInModel
@{
ViewBag.Title = "View";
}
<h2>View</h2>
@using (Html.BeginForm("SignIn", "Account", new { ReturnUrl = ViewBag.ReturnUrl }))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>SignInModel</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
Customer Index View
@{
ViewBag.Title = "Customers";
}
<h2>Customer</h2>
Focus on HttpGet SingIn action and SignIn view.
try: http://localhost:18908/Account/UnAuthorize?ReturnUrl=/Customer/Index