आप इस कोड, मास्टर पेज लोड घटना में जोड़ने एक संपत्ति की कोशिश, इस कोड लिख सकते हैं
सार्वजनिक bool m_bLoginRequired सच =;
public bool IsLoginRequired
{
get { return m_bLoginRequired; }
set { m_bLoginRequired = value; }
}
try
{
// Response.Cache.SetCacheability(HttpCacheability.ServerAndNoCache);
Response.Cache.SetNoStore();
if (IsLoginRequired==true)
{
if (Session.IsNewSession || HttpContext.Current.Session["Username"] == null)
{
FormsAuthentication.SignOut();
FormsAuthentication.RedirectToLoginPage("Session Expired");
Response.End();
}
}
}
catch (Exception ex)
{
throw (ex);
}
अब लॉग इन पेज में आप इस कोड
FormsAuthentication.SetAuthCookie(this.txt_UserName.Text.Trim(), false); FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, this.txt_UserName.Text.Trim(), DateTime.Now, DateTime.Now.AddMinutes(10), false, "HR");
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket));
cookie.Name = "jay";
Session["UserName"] = txt_UserName.Text.Trim();
Response.Cookies.Add(cookie);
txt_UserName.Text = "";
txt_Password.Text = "";
Response.Redirect("HomePage2.aspx");
अब आप प्रवेश पृष्ठ
protected void Page_PreInit(object sender, EventArgs e)
{
Master.IsLoginRequired = false;
}
में pageinit घटना जोड़ने के लिए एवेन्यू लिखने की ज़रूरत आप उपयोगकर्ता उपयोग कर सकते हैं कि चाहते हैं
सेट 01 के पेजिनिट ईवेंट में एक अधिकृत पृष्ठ
web.config
फ़ाइल में loginurl भी निर्दिष्ट करें।
स्रोत
2009-03-20 13:26:04
क्या आप 'अधिक सुधारी जा सकने वाली और प्रभावी' से क्या मतलब है? ऊपर उल्लिखित विधि के साथ क्या गलत है? –
मैंने वेब का उपयोग करते हुए नीचे जवाब दिया जब मैंने "लचीला" का अर्थ लिया।यदि आप इस तरह की चीज गतिशील पृष्ठों के साथ कर रहे हैं, या किसी पृष्ठ को उदाहरण के लिए पोस्ट की गई तारीख के आधार पर कॉन्फ़िग दर्द हो सकता है (यानी संग्रह पृष्ठों तक पहुंच प्रतिबंधित करना) –