How to put an excel file on my asp.net site in this case ? RRS feed

  • Question

  • User-775831949 posted

    I have a ASP.Net site with standard login

    I have a local windows application which can get www.someonething.com/somepath/MyExcel.xlsx file to get the data and this link can be modified.

    How can I provide instead an alternative link using links on my asp.net site like www.myasp.net/something.xlsx that is equivalent to this above but the machine is able to connect only when this pc login to the asp.net site ?


    Thursday, December 20, 2018 9:29 AM

All replies

  • User-893317190 posted

    Hi hkbeer,

    You could register a httphandler to deal with request ending with .xlsx and in the handler you could ensure the request is from local pc.

    Below is my code.

                                     //type = "your httphandler's namespace, the name of your assembly"
         <add name="excel" verb="*" path="*.xlsx" type="MyWebFormCases.Services.HandlerXslx, MyWebFormCases"/>

    In your httphandler.

     public void ProcessRequest(HttpContext context)
                context.Response.ContentType = "application/vnd.ms-excel";
                              //ensure the request is from local pc
                    if (HttpContext.Current.Request.UserHostAddress == "::1")
                        // write back the xlsx                    context.Response.WriteFile(HttpContext.Current.Request.MapPath(context.Request.Path));
                catch (Exception)

    For more information , you could refer to


    Best regards,

    Ackerly Xu

    Friday, December 21, 2018 2:20 AM