Click here to Skip to main content
15,867,885 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
i want to check the page extension like .txt or .xml in my project in global.asax.if it 's so , then redirect to another .aspx page.I don't know where to check this page extension in global.asax page.if it's having some setting in IIS or global events,then how do i do it?
Regards,
RAJNI PAL
Posted

1 solution

You need to handle Application_BeginRequest event of Global.asax file as following.

protected void Application_BeginRequest(object sender, EventArgs e)
    {

        string url = HttpContext.Current.Request.Url.AbsolutePath;
        string extension = System.IO.Path.GetExtension(url);
        switch (extension.ToLower())
        {
            case ".xml":
               //Do Somtething.
                break;
        }
    }
 
Share this answer
 
Comments
rajni 2 9-Jun-10 8:15am    
i tired this, but this begin request not called when i navigate to .xml page on button click.
PSK_ 9-Jun-10 8:17am    
Clear your browser cache; your xml file might be cached by your browser. Can you confirm that for normal .aspx pages this event is getting executed?
rajni 2 9-Jun-10 8:34am    
i'm having default.aspx page on which button is there,on their postbackurl="XMLFile.xml".at this time it's not come under Begin_Request function.so my extension doesn't get checked.and it's also n't opening XMLFile.xml. page n't found error 's coming
PSK_ 9-Jun-10 8:41am    
Try deleting your global.asax file and add it again.
PSK_ 9-Jun-10 8:47am    
Same this is working fine for me so it should also work for you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900