0

i have a page (APPLYforJOB.aspx), now if an registered user ahs signed in and clicked on APPLY for job Button then he will be promoted to page to fill his info but if he is hasn't logged in then he will be redirected to LOGIN.aspx page, I did it successfully but now i want to do something ike this , i want the Login Page to know that hwo its been accessed ? mean that is LOGIN page accessed normally or is it been requested from APPLYforJob.aspx page ? and on that basis i want to display message , That Please sign in before Applying for Job

applyforJob(.cs code)

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class applyForJob : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //string useremail =(string)Session["UserEmail"];
          int qryStrng_advId = int.Parse( Request.QueryString["advId"]);
          //lblAdvDetails.Text = "";

          Response.Write(qryStrng_advId);
    //    Response.Write("<br/>");
    //    Response.Write(useremail);


        //if (Session["UserEmail"] == null)
        //{
        //    Response.Redirect("~/loginMain.aspx");

        //}
        //else
        //{
        //    Response.Write("<br/>"+"Thanks for applying");
        //}

        String connectionString = "Data Source=COSANOSTRA;Initial Catalog=Waleed_orsfinal;Integrated Security=True";
        SqlConnection con = new SqlConnection(connectionString);
        String sqlQuery = "select advtitle,advDetails from tblJobAdv where advId=" + qryStrng_advId ;
        SqlCommand com = new SqlCommand(sqlQuery, con);
        SqlDataAdapter da = new SqlDataAdapter(com);
        DataSet ds = new DataSet();

        try
        {
            con.Open();
            da.Fill(ds, "tblJobAdv");
        }
        catch (Exception ex)
        {
            Response.Write("Error:" + ex.Message);
        }
        finally
        {
            con.Close();
        }

        datalistApplyForJob.DataSource = ds;
        datalistApplyForJob.DataBind();


    }
    protected void datalistApplyForJob_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void btnApplyJob_Click(object sender, EventArgs e)
    {
        if (Session["applicantSession"] == null)
        {
            Response.Redirect("~/loginApplicant.aspx");

        }
        else
        {
            Response.Write("<br/>" + "Thanks for applying");
        }
    }
}

***loginPage (.cs Code)
***

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.Data.SqlClient;
    public partial class applyForJob : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //string useremail =(string)Session["UserEmail"];
              int qryStrng_advId = int.Parse( Request.QueryString["advId"]);
              //lblAdvDetails.Text = "";

              Response.Write(qryStrng_advId);
        //    Response.Write("<br/>");
        //    Response.Write(useremail);


            //if (Session["UserEmail"] == null)
            //{
            //    Response.Redirect("~/loginMain.aspx");

            //}
            //else
            //{
            //    Response.Write("<br/>"+"Thanks for applying");
            //}

            String connectionString = "Data Source=COSANOSTRA;Initial Catalog=Waleed_orsfinal;Integrated Security=True";
            SqlConnection con = new SqlConnection(connectionString);
            String sqlQuery = "select advtitle,advDetails from tblJobAdv where advId=" + qryStrng_advId ;
            SqlCommand com = new SqlCommand(sqlQuery, con);
            SqlDataAdapter da = new SqlDataAdapter(com);
            DataSet ds = new DataSet();

            try
            {
                con.Open();
                da.Fill(ds, "tblJobAdv");
            }
            catch (Exception ex)
            {
                Response.Write("Error:" + ex.Message);
            }
            finally
            {
                con.Close();
            }

            datalistApplyForJob.DataSource = ds;
            datalistApplyForJob.DataBind();


        }
        protected void datalistApplyForJob_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        protected void btnApplyJob_Click(object sender, EventArgs e)
        {
            if (Session["applicantSession"] == null)
            {
                Response.Redirect("~/loginApplicant.aspx");

            }
            else
            {
                Response.Write("<br/>" + "Thanks for applying");
            }
        }
    }

    Login Page (.cs)Code

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.Data.SqlClient;

    public partial class loginApplicant : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {



        }
        protected void btnsubmit_Click(object sender, EventArgs e)
        {
            String hashedPwd = FormsAuthentication.HashPasswordForStoringInConfigFile(txtboxPassword.Text, "SHA1");
            //Response.Write(hashedPwd);
            String conString = "Data Source=COSANOSTRA;Initial Catalog=Waleed_orsfinal;Integrated Security=True";
            SqlConnection con = new SqlConnection(conString);
            String query = "select email,password from tblUser where email='" + txtboxUserEmail.Text + "' and password= '" + hashedPwd + "' ";
            SqlCommand com = new SqlCommand(query, con);

            try
            {
                con.Open();
                SqlDataReader dr = com.ExecuteReader();

                if (dr.Read() == true)
                {
                    Session["applicantSession"] = txtboxUserEmail.Text;
                    Response.Redirect("~/showAdvertsiement.aspx");
                }
                else
                {

                    Response.Write("Wrong Combination Of Email and Password");
                }
            }
            catch (Exception ex)
            {

                Response.Write("error" + ex.Message);


            }
            finally
            {
                con.Close();
            }
        }
    }
3
Contributors
2
Replies
4
Views
4 Years
Discussion Span
Last Post by JorgeM
1

@HunainHafeez, you can use Request.UrlReferrer to get the referrer server variable. This information is, however, supplied by the browser and is considered to be unreliable.

You could also pass along a querystring variable when you redirect that identifies the source page. For example:

if (Session["applicantSession"] == null)
{
  Response.Redirect("~/loginApplicant.aspx?source=application");
}
Votes + Comments
ok dear, now i want that user back to applyforjob page after successful login, automatically and this part confuses me
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.