Map
Changes
web-map/Controllers/AccountController.cs 13(+8 -5)
web-map/Controllers/BaseController.cs 23(+23 -0)
Details
web-map/Controllers/AccountController.cs 13(+8 -5)
diff --git a/web-map/Controllers/AccountController.cs b/web-map/Controllers/AccountController.cs
index 05d43ca..cfab058 100644
--- a/web-map/Controllers/AccountController.cs
+++ b/web-map/Controllers/AccountController.cs
@@ -41,8 +41,9 @@ namespace web_map.Controllers
[ValidateAntiForgeryToken]
public ActionResult Login(AuthModel model)
{
+ var WhereToGo = RequestUrl();
if (User.Identity.IsAuthenticated)
- Redirect("/Home/Index");
+ return Redirect("/Home/Index");
//RedirectToAction("Index");
// поиск пользователя в бд
@@ -56,8 +57,11 @@ namespace web_map.Controllers
{
FormsAuthentication.SetAuthCookie(user.Login, true);
user.IsAuth = true;
- return Redirect("/Home/Index");
- //RedirectToAction("Index");
+ if (WhereToGo != "/Account/Login")
+ return Redirect(WhereToGo);
+ else
+ return Redirect("/Home/Index");
+ //RedirectToAction("Index");
}
else
{
@@ -83,7 +87,6 @@ namespace web_map.Controllers
[HttpGet]
public ActionResult Logoff()
{
-
if (User.Identity.IsAuthenticated)
{
// поиск пользователя в бд
@@ -95,7 +98,7 @@ namespace web_map.Controllers
}
FormsAuthentication.SignOut();
- return Redirect("/Home/Index");
+ return Redirect(RequestUrl());
//RedirectToAction("Index");
}
web-map/Controllers/BaseController.cs 23(+23 -0)
diff --git a/web-map/Controllers/BaseController.cs b/web-map/Controllers/BaseController.cs
index 83d35bb..93a8c6b 100644
--- a/web-map/Controllers/BaseController.cs
+++ b/web-map/Controllers/BaseController.cs
@@ -20,5 +20,28 @@ namespace web_map.Controllers
ViewBag.UserName = (User.Identity.IsAuthenticated) ? User.Identity.Name : "NoAuth";
}
+ protected string RequestUrl()
+ {
+ var request = Request.RequestContext.HttpContext.Items["MS_HttpRequestMessage"].ToString();
+
+ var start = request.IndexOf(' ', request.IndexOf("Referer") + 1);
+ var end = request.IndexOf('\r', start + 1);
+
+ var u = request.Substring(start + 1, end - start - 1).Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
+
+ string controller, action;
+ if (u.Length > 3)
+ {
+ controller = u[2];
+ action = u[3];
+ }
+ else
+ {
+ controller = "Home";
+ action = "Index";
+ }
+ return '/' + controller + '/' + action;
+ }
+
}
}
\ No newline at end of file