मैं जिसके लिए मैं प्राधिकरण को लागू कर रहा हूँ मेरे अपने लॉगिन दृश्य है जो उपयोगकर्ताओं को नाम और पासवर्ड अनुमति दी जाती है अगर जाँच करता है और उसके बाद सत्र कि कहने के लिए में एक चर सेट का उपयोग कर एक MVC 3 एप्लिकेशन है उपयोगकर्ता को लॉग इन किया जाता है। इस तरह के काम लेकिन एक विशेष विचार के लिए यह एक अजीब अवांछित तरीके से व्यवहार कर रहा है। कहा गया दृश्य एक ऐसा फॉर्म है जिसका उपयोग मैं कुछ डेटा इनपुट करने और फ़ाइल अपलोड करने के लिए करता हूं। किसी कारण से मैं समझ नहीं पा रहा हूं, इस फ़ॉर्म को पोस्ट करने के बाद एक नया सत्र शुरू हो गया है और इसलिए वेरिएबल जो याद करता है कि उपयोगकर्ता लॉग इन था, उसे गलत पर रीसेट कर दिया गया है और बाद में लॉगिन पेज फिर से प्रदर्शित होता है।ASP.Net MVC 3 अजीब सत्र व्यवहार
मैं क्यों आवेदन इस बिंदु पर एक नया सत्र शुरू हो रहा है के रूप में खो दिया है कर रहा हूँ? मैंने इसे करने के लिए निर्देश नहीं दिया है। क्या कोई इस व्यवहार को रोकने और पुराने सत्र को रखने के लिए समाधान सुझा सकता है?
धन्यवाद।
अद्यतन - कुछ कोड:
नोट सत्र तैनात Create
प्रपत्र के जवाब के बाद तुरंत समाप्त किया जा रहा है
सीएमएस नियंत्रक जो एक कस्टम Autorize विशेषता "RDAutorize" पर बुलाया का उपयोग करता है सभी कार्यों:
[RDAuthorize]
public class PhotoCMSController : Controller
{
public ActionResult Create()
{
/* Code omitted: set up a newPhoto object with default state */
/* Display view containing form to upload photo and set title etc. */
return View("../Views/PhotoCMS/Create", newPhoto);
}
[HttpPost]
public ContentResult Upload(int pPhotoId)
{
/* Code ommited: receive and store image file which was posted
via an iframe on the Create view */
string thumbnail = "<img src='/path/to/thumb.jpg' />";
return Content(thumbnail);
}
[HttpPost]
public ActionResult Create(string pPhotoTitle, string pCaption etc...)
{
/*Code omitted: receive the rest of the photo data and save
it along with a reference to the image file which was uploaded
previously via the Upload action above.*/
/* Display view showing list of all photo records created */
return View("../Views/PhotoCMS/Index", qAllPhotos.ToList<Photo>());
/* **Note: after this view is returned the Session_End() method fires in
the Global.asax.cs file i.e. this seems to be where the session is
being lost** */
}
}/*End of CMS Controller*/
कस्टम अधिकृत कार्रवाई फिल्टर:
public class RDAuthorize : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
Boolean authorized = Convert.ToBoolean(
HttpContext.Current.Session["UserIsAuthorized"]
);
if (!authorized) {
/* Not logged in so send user to the login page */
filterContext.HttpContext.Response.Redirect("/Login/Login");
}
}
public override void OnActionExecuted(ActionExecutedContext filterContext) {}
public override void OnResultExecuting(ResultExecutingContext filterContext) {}
public override void OnResultExecuted(ResultExecutedContext filterContext) {}
}/*End of Authorize Action Filter*/
लॉग इन नियंत्रक:
public class LoginController : Controller
{
private PhotoDBContext _db = new PhotoDBContext();
public ActionResult Login()
{
string viewName = "";
Boolean authorized = Convert.ToBoolean(Session["UserIsAuthorized"]);
if (authorized)
{
viewName = "../Views/Index";
}
else
{
viewName = "../Views/Login/Login";
}
return View(viewName);
}
[HttpPost]
public ActionResult Login(string pUsername, string pPassword)
{
string viewName = "";
List<Photo> model = new List<Photo>();
var qUsers = from u in _db.Users
select u;
foreach (User user in qUsers.ToList<User>())
{
/* If authorized goto CMS pages */
if (pUsername == user.Username && pPassword == user.Password)
{
Session["UserIsAuthorized"] = true;
var qPhotos = from p in _db.Photos
where p.IsNew == false
select p;
model = qPhotos.ToList<Photo>();
viewName = "../Views/PhotoCMS/Index";
break;
}
}
return View(viewName, model);
}
}/* End of Login controller */
पहले कोड जोड़ने के लिए क्षमा नहीं। मुझे उम्मीद है कि उपर्युक्त उपयोगी है। –
इस पोस्ट के लिए धन्यवाद, मैंने सीखा कि प्राधिकरण का उपयोग कैसे करें। – sed