Here is the code I used and works perfectly in VS 2008 but not on IIS7.
public void sendm (string ename,string leaveid, string empid,string tomail,string frommail)
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient(MServerName);
mail.From = new MailAddress(frommail);
mail.To.Add(tomail);
mail.Subject = "Leave Request: "+ename+" Has Applied for Leave";
mail.IsBodyHtml = true;
mail.Body = "Dear Manager </br> </br> Please approve leave of: "+ename+" : <a href='http://localhost:60457/blbtrc/LeaveApproval.aspx?leavetrnumber="+leaveid+"&UserID="+empid+"'>Click to Approve </a>";
SmtpServer.Port = Convert.ToInt32(MServerPort);
SmtpServer.EnableSsl = false;
SmtpServer.Send(mail);
}
My site is configure on port 82 in IIS and if I change the mail.body to
mail.Body = "Dear Manager </br> </br> Please approve leave of: " + ename + " : <a href='http://localhost:82/blbtrc/LeaveApproval.aspx?leavetrnumber=" + leaveid + "&UserID=" + empid + "'>Click to Approve </a>";
Clicking on link in the mail does not open the gird with the information when I am using IIS.
My grid view in the page is as below:
<asp:GridView ID="LeaveDate" runat="server" AutoGenerateColumns="False"
DataKeyNames="Leave_ID" DataSourceID="LeaveApprovalSD1">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="Leave_ID" HeaderText="Leave_ID"
SortExpression="Leave_ID" ReadOnly="True" InsertVisible="False" />
<asp:BoundField DataField="LeaveTRNumber" HeaderText="LeaveTRNumber"
SortExpression="LeaveTRNumber"/>
<asp:BoundField DataField="Employee_Name" HeaderText="Employee_Name"
SortExpression="Employee_Name" />
<asp:BoundField DataField="Leave_StDate" HeaderText="Leave_StDate"
SortExpression="Leave_StDate"/>
<asp:BoundField DataField="Leave_EdDate" HeaderText="Leave_EdDate"
SortExpression="Leave_EdDate"/>
<asp:BoundField DataField="Numb_Of_days" HeaderText="Numb_Of_days"
SortExpression="Numb_Of_days" />
<asp:BoundField DataField="LeaveStatus" HeaderText="LeaveStatus"
SortExpression="LeaveStatus" />
<asp:BoundField DataField="Rejection_Summary"
HeaderText="Rejection_Summary" SortExpression="Rejection_Summary" />
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True"
CommandName="Update" Text="Update"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
CommandName="RowEditing" Text="Edit"></asp:LinkButton>
</ItemTemplate>
<ItemTemplate>
<asp:Button ID="ApproveBtn" runat="server" Text="Approve" OnClick="Approve_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="LeaveApprovalSD1" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
DeleteCommand="DELETE FROM [LeaveTracking] WHERE [Leave_ID] = @original_Leave_ID AND (([LeaveTRNumber] = @original_LeaveTRNumber) OR ([LeaveTRNumber] IS NULL AND @original_LeaveTRNumber IS NULL)) AND (([Employee_Name] = @original_Employee_Name) OR ([Employee_Name] IS NULL AND @original_Employee_Name IS NULL)) AND (([Leave_StDate] = @original_Leave_StDate) OR ([Leave_StDate] IS NULL AND @original_Leave_StDate IS NULL)) AND (([Leave_EdDate] = @original_Leave_EdDate) OR ([Leave_EdDate] IS NULL AND @original_Leave_EdDate IS NULL)) AND (([Numb_Of_days] = @original_Numb_Of_days) OR ([Numb_Of_days] IS NULL AND @original_Numb_Of_days IS NULL)) AND (([LeaveStatus] = @original_LeaveStatus) OR ([LeaveStatus] IS NULL AND @original_LeaveStatus IS NULL)) AND (([Rejection_Summary] = @original_Rejection_Summary) OR ([Rejection_Summary] IS NULL AND @original_Rejection_Summary IS NULL))"
InsertCommand="INSERT INTO [LeaveTracking] ([LeaveTRNumber], [Employee_Name], [Leave_StDate], [Leave_EdDate], [Numb_Of_days], [LeaveStatus], [Rejection_Summary]) VALUES (@LeaveTRNumber, @Employee_Name, @Leave_StDate, @Leave_EdDate, @Numb_Of_days, @LeaveStatus, @Rejection_Summary)"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT [Leave_ID], [LeaveTRNumber], [Employee_Name], [Leave_StDate], [Leave_EdDate], [Numb_Of_days], [LeaveStatus], [Rejection_Summary] FROM [LeaveTracking] WHERE ([LeaveTRNumber] = @LeaveTRNumber) and ([LeaveStatus] =@LeaveStatus)"
UpdateCommand="UPDATE [LeaveTracking] SET [Rejection_Summary] = @Rejection_Summary WHERE [Leave_ID] = @original_Leave_ID AND (([LeaveTRNumber] = @original_LeaveTRNumber) OR ([LeaveTRNumber] IS NULL AND @original_LeaveTRNumber IS NULL)) AND (([Employee_Name] = @original_Employee_Name) OR ([Employee_Name] IS NULL AND @original_Employee_Name IS NULL)) AND (([Leave_StDate] = @original_Leave_StDate) OR ([Leave_StDate] IS NULL AND @original_Leave_StDate IS NULL)) AND (([Leave_EdDate] = @original_Leave_EdDate) OR ([Leave_EdDate] IS NULL AND @original_Leave_EdDate IS NULL)) AND (([Numb_Of_days] = @original_Numb_Of_days) OR ([Numb_Of_days] IS NULL AND @original_Numb_Of_days IS NULL)) AND (([LeaveStatus] = @original_LeaveStatus) OR ([LeaveStatus] IS NULL AND @original_LeaveStatus IS NULL)) AND (([Rejection_Summary] = @original_Rejection_Summary) OR ([Rejection_Summary] IS NULL AND @original_Rejection_Summary IS NULL))">
<SelectParameters>
<asp:QueryStringParameter Name="LeaveTRNumber" QueryStringField="LtrNo"
Type="String" />
<asp:QueryStringParameter Name="LeaveStatus" QueryStringField="LeaveStatus"
Type="String" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="original_Leave_ID" Type="Int32" />
<asp:Parameter Name="original_LeaveTRNumber" Type="String" />
<asp:Parameter Name="original_Employee_Name" Type="String" />
<asp:Parameter DbType="Date" Name="original_Leave_StDate" />
<asp:Parameter DbType="Date" Name="original_Leave_EdDate" />
<asp:Parameter Name="original_Numb_Of_days" Type="String" />
<asp:Parameter Name="original_LeaveStatus" Type="String" />
<asp:Parameter Name="original_Rejection_Summary" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Rejection_Summary" Type="String" />
<asp:Parameter Name="original_Leave_ID" Type="Int32" />
<asp:Parameter Name="original_LeaveTRNumber" Type="String" />
<asp:Parameter Name="original_Employee_Name" Type="String" />
<asp:Parameter DbType="DateTime" Name="original_Leave_StDate" />
<asp:Parameter DbType="DateTime" Name="original_Leave_EdDate" />
<asp:Parameter Name="original_Numb_Of_days" Type="String" />
<asp:Parameter Name="original_LeaveStatus" Type="String" />
<asp:Parameter Name="original_Rejection_Summary" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="LeaveTRNumber" Type="String" />
<asp:Parameter Name="Employee_Name" Type="String" />
<asp:Parameter DbType="Date" Name="Leave_StDate" />
<asp:Parameter DbType="Date" Name="Leave_EdDate" />
<asp:Parameter Name="Numb_Of_days" Type="String" />
<asp:Parameter Name="LeaveStatus" Type="String" />
<asp:Parameter Name="Rejection_Summary" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
and I capture the value in the code as below:
protected void Page_Load(object sender, EventArgs e)
{
LTRno = Request.QueryString["leavetrnumber"].ToString()
if (!IsPostBack)
{
----------
Levaedatasource.SelectParameters["Leave_StDate"].DefaultValue = lstdate;
Levaedatasource.SelectParameters["Leave_StDate2"].DefaultValue = leddate;
LeaveApprovalSD1.SelectParameters["LeaveTRNumber"].DefaultValue = LTRno;
}
}
Your email generation code generates a URL with the query string parameters leavetrnumber
and UserID
. But your query string parameters for your SqlDataSource
is looking for LtrNo
and LeaveStatus
. You probably need those to match for your SqlDataSource
to retrieve the results. Grabbing the values in the Page_Load
function doesn't automatically pass them into parameters in your data source.
Looking at your updated question, you have two options. You can get the query string to match like I described above. Or you can make sure you rebind the GridView after assigning the values to the parameters. Ex:
var LTRno = Request.QueryString["leavetrnumber"]
LeaveApprovalSD1.SelectParameters["LeaveTRNumber"].DefaultValue = LTRno;
LeaveDate.DataBind();
I don't like this approach, because the whole point of using a QueryStringParameter in your SqlDataSource is that you shouldn't need to have code wire up the parameters. You should just make the parameters match.
One other thing to fix is that your URL in the email generation code needs to point to the server. Localhost is the loopback address 127.0.0.1, and will always go to the local machine. You need to provide the dns name of the server (perhaps the host name, or you may have an alias set up).