As Per Your Request, Here I'm posting the whole thing right from the Starting of adding Web.config.
Step-1: Place a 'login.aspx' form in your Application & Write the Following code in it under Sign In button:
protected void Button1_Click(object sender, EventArgs e)
{
Session["HiddenID"] = true;
}
Step-2: Now I'm going to check whether Session variable exists or not when user is clicking Download Link. Here I'm using a Button for implementing Download logic:
protected void Button1_Click(object sender, EventArgs e)
{
if (Session["HiddenID"] != null || Session["FrontHiddenID"] != null)
{
string fileName = <provide your filename here>;
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName);
Response.TransmitFile(Server.MapPath("~/Doc/" + fileName));
Response.End();
}
else
Response.Redirect("login.aspx");
}
I guess this should work for you.
Checked in my System & Works fine for me.
Let me know if it's working for you or not.