Question : messages are acting weird.

if you goto omegalove and open two browsers
one user  username: mathew pass: mathew
sec user  username: Teresa   pass: Teresa

Now if these two are reply to a message it seems like the message comes back as if the message was sent from the other user.

Please see code and diagram attached,
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web.Security;
using System.Web;
using System.Web.Profile;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
using System.Web.UI.HtmlControls;
using System.Threading;
using System.Text;
using System.Net;
using System.IO;
using OmegaLove.BLL;
using DataTransfer.Tables;

namespace OmegaLove.Web.UI.Pages
{
    public partial class ShowMessage : OmegaLoveBasePage
    {
        private static string UserId = null;
        private static string ToUserProfileID = null;
        private static string FromUserProfileID = null;
        private static string FromUserName = null;
        private static string ToUserName = null;
        private static string ToUserEmailAddress = null;
        private static string UserEmailAddress = null;
        private static string MessageID, InitialMessageID = null;

        private static tbl_Messages tbl_Messages = new tbl_Messages();

        public static string ConnnectionString = ConfigurationManager.ConnectionStrings["omegaloveConnectionString"].ToString();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!(HttpContext.Current.User.Identity.IsAuthenticated))
                Response.Redirect("~/Login.aspx");

            if (!IsPostBack)
            {
                if (Request.QueryString.HasKeys() && !String.IsNullOrEmpty(Request.QueryString["MessageId"]))
                {

                    MessageID = Request.QueryString["MessageID"];
                    FromUserProfileID = Request.QueryString["FromProfileID"];
                    FromUserName = Request.QueryString["FromUsername"];
                    ToUserName = Session["FromUserName"] == null ? null : Session["FromUserName"].ToString();
                    lblFrom.Text = "From";
                    lblTo.Text = "To";
                    lblTime.Text = "Date Sent";
                    lblSubject.Text = "Subject";
                    lblMess.Text = "Message";
                    GetMessage(MessageID);
                    DisplayUserImage();
                }

            }
        }

        private void GetMessage(string MessageID)
        {
            DataTable dtMessage = new DataTable();

            dtMessage = DataBase.Procedures.prc_Messages_Select.ToDataTable(ConnnectionString, Convert.ToInt32(MessageID));


            DataTable dtToEmail = new DataTable();
            DataTable dtFromEmail = new DataTable();
            dtToEmail = DataBase.Procedures.prc_Profile_Select.ToDataTable(ConnnectionString, FromUserName);
            dtFromEmail = DataBase.Procedures.prc_Profile_Select.ToDataTable(ConnnectionString, ToUserName);
            ToUserEmailAddress = dtToEmail.Rows[0]["EmailAddress"].ToString();
            UserEmailAddress = dtFromEmail.Rows[0]["EmailAddress"].ToString();
            ToUserProfileID = dtFromEmail.Rows[0]["ProfileID"].ToString();
            lblMessage.Text = dtMessage.Rows[0]["Body"].ToString();
            lblFromUsername.Text = dtMessage.Rows[0]["FromUserName"].ToString();
            lblToUsername.Text = ToUserName;
            lblToUser.Text = FromUserName;

            lblMessageTime.Text = dtMessage.Rows[0]["MsgDate"].ToString();
            lblMessage.Text = dtMessage.Rows[0]["Body"].ToString();
            lblSubjectMessage.Text = dtMessage.Rows[0]["Subject"].ToString();

            InitialMessageID = dtMessage.Rows[0]["InitialMessageID"].ToString();


        }

        protected void SubmitMessage_Click(object sender, ImageClickEventArgs e)
        {
            if (Page.IsValid)
            {
                

                if (MessageID == "0")
                {
                    // New Messages
                    sendMessage();
                }
                else
                {
                    // For Reply Messages

                    if (InitialMessageID == "0")
                        InitialMessageID = MessageID;

                    sendMessage(true, Convert.ToString(MessageID), InitialMessageID);
                }

            }
        }

        private void sendMessage()
        {
            sendMessage(false, null, null);
        }

        private void sendMessage(Boolean IsReply, string CurrentMessageID, string InitialMessageID)
        {
            tbl_Messages tbl_Messages = new tbl_Messages();
            tbl_Messages.ProfileID = Convert.ToInt32(FromUserProfileID);
            tbl_Messages.FromProfileID = Convert.ToInt32(ToUserProfileID);
            tbl_Messages.Subject = txtSubject.Text;
            tbl_Messages.Body = txtMessage.Text;
            tbl_Messages.FromUsername = ToUserName;
            tbl_Messages.MsgDate = DateTime.Now;
            tbl_Messages.MsgNew = 1;
            tbl_Messages.MsgRead = 1;
            tbl_Messages.MsgReplied = Convert.ToByte(IsReply); // New Message (0) / Reply Message (1)

            if (IsReply)
            {
                tbl_Messages.ReplyOfMessageID = Convert.ToInt32(CurrentMessageID);
                tbl_Messages.InitialMessageID = Convert.ToInt32(InitialMessageID);
            }

            int returnValue = 0;
            try
            {
                returnValue = DataBase.prc_Messages_Save.Execute(ConnnectionString, tbl_Messages);

                if (returnValue > 0)
                {
                    SMTPManager.SendEmail(UserEmailAddress, FromUserName, ToUserEmailAddress, txtMessage.Text, txtSubject.Text, false);
                }
            }
            catch (Exception)
            {
                throw;

            }

            //lblMessage.Text = "Mail sent successfully!";
            //Thread.Sleep(2000);
            Response.Redirect("~/Secure/MailBox.aspx");
        }

        private void DisplayUserImage()
        {

            DataTable dt = new DataTable();

            dt = DataBase.Procedures.prc_Profile_Select.ToDataTable(ConnnectionString, FromUserName);

            DataTable dtPhotos = new DataTable();

            dtPhotos = DataBase.Procedures.prc_Photos_Select_Primary.ToDataTable(ConnnectionString, Convert.ToInt32(dt.Rows[0]["ProfileID"]));


            // Get img id from datatable.
            if (((dtPhotos != null) && (dtPhotos.Rows.Count > 0)))
            {
                if (Convert.ToBoolean(dtPhotos.Rows[0]["p_Primary"]))
                {
                    imgPhoto.ImageUrl = "ShowImage.ashx?img_id=" + dtPhotos.Rows[0]["PhotoID"].ToString() + "&" + "imagesize=T" + "&" + "imageisprimary=" + "True" + "'";

                }
                else
                {
                    if (dt.Rows[0]["Gender"].ToString() == "1")
                        imgPhoto.ImageUrl = "~/Images/NoPictures/no_photo_white_m_m.jpg";
                    else
                        imgPhoto.ImageUrl = "~/Images/NoPictures/no_photo_white_f_m.jpg";
                }
            }
            else // There is no primary image.
            {
                if (dt.Rows[0]["Gender"].ToString() == "1")
                    imgPhoto.ImageUrl = "~/Images/NoPictures/no_photo_white_m_m.jpg";
                else
                    imgPhoto.ImageUrl = "~/Images/NoPictures/no_photo_white_f_m.jpg";
            }
        }
    }
}
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/TwoColumn.master" AutoEventWireup="true"
    CodeBehind="ShowMessage.aspx.cs" Inherits="OmegaLove.Web.UI.Pages.ShowMessage" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>

<asp:Content ID="Content1" ContentPlaceHolderID="cph2" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cph1" runat="server">
    <script type="text/javascript">

    function ismaxlength(obj) {
        var mlength = obj.getAttribute ? parseInt(obj.getAttribute("maxlength")) : ""
        if (obj.getAttribute && obj.value.length > mlength)
            obj.value = obj.value.substring(0, mlength)
    }

    function textCounter(field, countfield, maxlimit) {
        if (field.value.length > maxlimit) {
            field.value = field.value.substring(0, maxlimit);
        }
        else {
            countfield.value = maxlimit - field.value.length;
        }
    }
</script>
    <div id="show-message">
        <asp:Image ID="imgPhoto" CssClass="photo" runat="server"></asp:Image>
        <div id="message-details">
            <asp:Label ID="lblFrom" runat="server"></asp:Label>: <b>
                <asp:Label ID="lblFromUsername" runat="server"></asp:Label></b><br>
            <asp:Label ID="lblTo" runat="server"></asp:Label>: <b>
                <asp:Label ID="lblToUsername" runat="server"></asp:Label></b><br>
            <asp:Label ID="lblSubject" runat="server"></asp:Label>: <b>
                <asp:Label ID="lblSubjectMessage" runat="server"></asp:Label></b><br>
            <asp:Label ID="lblTime" runat="server"></asp:Label>: <b>
                <asp:Label ID="lblMessageTime" runat="server"></asp:Label></b><br>
            <asp:Label ID="lblMess" runat="server"></asp:Label>: <b>
                <asp:Label ID="lblMessage" CssClass="message-content"  runat="server"></asp:Label></b>
        </div>
        <div class="clear">
        </div>
       
    </div>
    <div id="CntUserPage">
        <div class="outbox">
            <table cellpadding="3" cellspacing="0" width="500px">
                <tr>
                    <td class="msgData">
                        <div class="h2 t_sprite mail_send">
                            Reply to message...&hellip;
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="msgData">
                        <table cellpadding="3" cellspacing="1">
                            <tr>
                                <td>
                                    To :
                                </td>
                                <td nowrap>
                                    <asp:Label ID="lblToUser" runat="server"></asp:Label>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Subject&nbsp;:&nbsp;&nbsp;
                                </td>
                                <td>
                                    &nbsp;<asp:TextBox ID="txtSubject" MaxLength="50" runat="server" BorderColor="DarkGray"
                                        CssClass="textBox" />
                                    <asp:RequiredFieldValidator ID="RFVtxtSubject" runat="server" ControlToValidate="txtSubject"
                                        ErrorMessage="<b>Required Field Missing.</b><br />Subject is required." Font-Size="X-Small"
                                        SetFocusOnError="true" Display="None"></asp:RequiredFieldValidator>
                                    <ajaxToolkit:ValidatorCalloutExtender runat="Server" ID="RFVtxtSubjectE" TargetControlID="RFVtxtSubject"
                                        HighlightCssClass="validatorCalloutHighlight" />
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
            <table cellspacing="0" cellpadding="10" width="500px">
                <tr>
                    <td class="msgData" colspan="2">
                        <asp:TextBox ID="txtMessage" CssClass="textarea" MaxLength="1000" TextMode="MultiLine"
                            Width="90%" Rows="10" Columns="60" runat="server" onkeydown="textCounter(this,this.form.message,1000);"
                            onkeyup="return ismaxlength(this)" /><br />
                        <asp:RequiredFieldValidator ID="RFVtxtMessage" runat="server" ControlToValidate="txtMessage"
                            ErrorMessage="<b>Required Field Missing.</b><br />Message is required." Font-Size="X-Small"
                            SetFocusOnError="true" Display="None"></asp:RequiredFieldValidator>
                        <ajaxToolkit:ValidatorCalloutExtender runat="Server" ID="RFVtxtMessageE" TargetControlID="RFVtxtMessage"
                            HighlightCssClass="validatorCalloutHighlight" />
                    </td>
                </tr>
                <tr>
                    <td class="msgData">
                        <asp:ImageButton ID="SubmitMessage" ImageUrl="~/Images/Buttons/send_email.gif" runat="server"
                            OnClick="SubmitMessage_Click" />
                    </td>
                    <td class="msgData right">
                        <input style='font-size: 1.0em; color: #000; font-family: Arial' maxlength="3" name="message"
                            readonly="readonly" size="3" value="1000" /><span class="smallBlue">( 1000 max )</span>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</asp:Content>
Attachments:
 
diagram attached,
diagram attached,
 

Answer : messages are acting weird.

I would recommend you to use a sysinternals utility called process explorer. It will tell you exactly what you want. you can download it from here

http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx
Random Solutions  
 
programming4us programming4us