[RESOLVED]Help with Moving Sensitive data across PAges

notifyID UserID User_ID notifyMessage                                                                                                        IsSeen

4 8 3 Craig Blewett has recommended your story ‘State of the Game finds Premier League ‘a third English” /readpost/@hardweezy/283577427 11/29/2014 8:30:29 PM False
5 8 3 Craig Blewett has archived your story ‘State of the Game finds Premier League ‘a third English” /readpost/@hardweezy/283577427 11/29/2014 8:30:33 PM False
6 8 3 Craig Blewett is now following you /Profile/@craig 11/29/2014 8:30:41 PM False
             

I have a page called notification that shows current users recent activity on the use of the website.. The page does two things, If notify row is Fals (IsSeen), it sets the background to dark color, if (IsSeen) it marks it as White.. I do not want to perform
the table update on the notification table, I want users to click the notification message and the pageStart does the rest when the link goes live.

This is my code below

 @foreach(var d in notify){
    @{Session["id"]=d.notifyID;}
     var sender=db.QuerySingle("select * from Userprofile where UserID=@0",d.UserID);      
  if(d.IsSeen==false){
      
 

                          <div class="col-md-10 col-sm-10 notesList" style="background-color: #F5F8FA;" onclick="window.location = '@Href("~/"+d.URL)';"> 
  
               <div class=" col-xs-2" style="float: left! important;">
                       <img src="~/img/@sender.ProfilePic" class="this-icony" alt="@sender.Fname"  style="float: left! important">
                           </div>
                        <div class="col-xs-10"style="">
                        <div class="notesAuthor">@sender.Fname<span class="notesContent">&nbsp;<i class="fa fa-at"></i>@sender.Username &nbsp;&nbsp;@String.Format("{0:MMM.dd}", d.notifyDate)</span> </div>
<div class="notesContent">@d.notifyMessage</div>                                  
<span class="noteContent"><i class="fa fa-share-square"></i> <i class="fa fa-thumbs-o-up"></i> <i class="fa fa-link"></i></span>
               </div>      
                                 
                    </div>}
    else{
 
        <div class="col-md-10 col-sm-10 notesList" onclick="window.location = '@Href("~/"+d.URL)';"> 
  
               <div class=" col-xs-2" style="float: left! important;">
                       <img src="~/img/@sender.ProfilePic" class="this-icony" alt="@sender.Fname"  style="float: left! important">
                           </div>
                        <div class="col-xs-10"style="">
                        <div class="notesAuthor">@sender.Fname<span class="notesContent">&nbsp;<i class="fa fa-at"></i>@sender.Username &nbsp;&nbsp;@String.Format("{0:MMM.dd}", d.notifyDate)</span> </div>
<div class="notesContent">@d.notifyMessage</div>                                  
<span class="noteContent"><i class="fa fa-share-square"></i> <i class="fa fa-thumbs-o-up"></i> <i class="fa fa-link"></i></span>
               </div>      
                                 
                    </div>
    }                      
   }      

I tried putting the looped ID into a Session["id"] and then check if its null at pageStart, if not null update Table where (int)Session["id] is valid.

The problem I get is, whenever I test for the Session Variable, It always returns 4 back, no matter the link I click. I need help rectifying this.. I have tested the d.notifyID over and over again, but it gives me the correct ID everytime. except for the Session["id"]..

If you are setting the Session within the loop like this :

@foreach(var d in notify){
    @{Session["id"]=d.notifyID;}
}

Then the Session["id"] value is always going to equal the value that it was last set as (e.g. the last item in your loop). If you need to access the specific value for each of your links, you might consider adding it as a QueryString parameter when
looping through :

<div class="col-md-10 col-sm-10 notesList" onclick="window.location = '@Href("~/"+d.URL +"?notify=" + d.notifyId)';"> 

Now, its going to mess up my URL, but it solves the problem though..I was looking for cleaner ways to solve this

Honestly, this is a fairly common approach (using QueryString parameters) and it will be much more maintainable as opposed to using the Session, which can present all sorts of resource issues.

Rion Williams

Honestly, this is a fairly common approach (using QueryString parameters) and it will be much more maintainable as opposed to using the Session.

QueryString is a common approach, but the UrlData is a fair approach. It seems better to use them. 

If you’re talking about, string or numeric data type issues then they would be in the UrlData or QueryString too once you use them in the code-behind. 

Leave a Reply