Users with MasterPage

1

I am trying the following: I have a Sitie1.Master with 3 related pages, and a page Default.aspx (That is not related to the MasterPage), the user puts his email in a TextBox (Login in Default.aspx ) I want that value that I keep in String , show it in a Label in the 3 pages of content, for now I have that:

    public String Usuario
    {
        get { return (String)ViewState["Usuario"]; }
        set { ViewState["Usuario"] = value; }
    }

        void Page_Init(Object sender, EventArgs e)
    {
        //Recibir valor de Default.aspx
        String id = Request.QueryString["Valor"];
        this.Usuario = id;
        LblID.Text = id;
    }

I do not know if this is wrong, I do not know how to send that value of Default.aspx or if there is another way of wanting to do that.

    
asked by CarlosR93 07.04.2017 в 19:54
source

2 answers

2

One of the problems of sending information in the URL and obtaining them via QueryString is that the user can modify the URL , so you have to take extra precautions when dealing with this information. Using ViewState might work, but the problem is that your information "persists" as long as you stay on the page where you stored the content. In addition, every postback that is carried out sends all the information it has, which consumes more bandwidth. If you then change pages, the information you stored on the previous page will no longer be available.

An alternative is the use of session variables , You can create one in a Default.aspx:

Session["correo"] = cajaTextoCorreo.Text;

And then use it on your other pages, for example:

protected void Page_Load(object sender, EventArgs e)
{
       correo= Session["correo"].ToString();
}

As cons, is that it consumes resources on the server side, and the session variables are linked to the client's session, but this information will be available on all pages, until the session dies.

    
answered by 07.04.2017 / 20:17
source
2

Hi, you could store it as a session variable to the current user

session["Usuario"] = Request.QueryString["valor"];

then in the master page to not be placing it in each view to define it in the header usually to be shared with the remains add in Sitie1.Master .

<span ID="lblUsuario" runat="server"></span>

In the page load of the master pay Sitie1.Master.cs add:

lblUsuario.InnerHtml = session["Usuario"];

With this it should work.

Greetings

    
answered by 07.04.2017 в 20:19