Restrict Pdf File when user logout

Posted by Venkatesh under ASP.NET on 12/2/2010 | Points: 10 | Views : 1781 | Status : [Member] | Replies : 3
Hi,

I am generating pdf file when he is login.In that login i used sessions.After that when generating pdf file that will be saved in the report folder that folder will be in project folder.When generating pdf file some url will be appeared like

http://localhost/Demo/Administration/Reports/Report Documents/12-Mar-2010 10 49 44eNETSExceptions.pdf this will be appeared in the browser

When he copy the url and enters into another browser i dont want allow to open that pdf that will be redirect to login page.How to do this

Thanks
Venkatesh




Responses

Posted by: Vuyiswamb on: 12/2/2010 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
When he Logout abondon the Session or set it to null, and every time a user access that page , check if the Session is null or not

Thank you for posting at Dotnetfunda
[Administrator]

Venkatesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Venkatesh on: 12/2/2010 [Member] Starter | Points: 25

Up
0
Down
Hi,

Thaks for reply after he logout sessions will be removed and when he copy that url pdf will be opening in the browser other than pdf file all pages are redirected to login page.

So my question is: when he paste the url i want to redirect to login page. remember it is pdf not aspx page

in the global.asax file i write this code

void Application_AcquireRequestState(object sender, EventArgs e)
{
string sPath = Context.Request.Path.ToLower();

string sPage = sPath.Substring(sPath.LastIndexOf("/") + 1);
//Session is Available here
if (sPage.EndsWith(".pdf"))
{
HttpContext con = HttpContext.Current;
if (con.Session["USER_ID"]!=null)
{
string str = Session["USER_ID"].ToString();
}
}

}

Every request will be handle here but when pdf comes the session will not handle how to check this

how to do this

Venkatesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 12/2/2010 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
ok lets say when he login to your system, if the creadentials are correct, you must store the username in a session variable, and when he logs out , in the button or link that he will use to logout , set the session that you stored the username to null or use Session.Abondon. Now in your page you should have something like this


if(Session["Username"] == null)
{
response.Redirect("Login.aspx",false);
}


this is the way you should do it.

Thank you for posting at Dotnetfunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

Venkatesh, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response