简体   繁体   English

Excel报告未授权错误链接

[英]Excel report unauthorized error link

I am making excel report of my SQL server table records. 我正在制作我的SQL Server表记录的excel报告。 In Asp page grid view I am fetching required data then this data is downloaded in excel. 在Asp页面网格视图中,我正在获取所需的数据,然后在excel中下载此数据。 one column has hyperlink value & I need this hyperlink should only work in Asp page Grid view but after download, it should redirect to a new page where Unauthorized access error will be shown. 一列具有超链接值,我需要此超链接仅应在“ Asp”页面“网格”视图中工作,但下载后,应重定向到新页面,在该页面上将显示未授权访问错误。 I am not getting how to show unauthorized error link in excel file hyperlink click. 我没有得到如何在Excel文件超链接单击中显示未经授权的错误链接。
Here is my code 这是我的代码

protected void LnkBtnViewImage_Click(object sender, EventArgs e)
    {

        SqlConnection con = new SqlConnection(cs);

        LinkButton lnkbtimage = sender as LinkButton;
        GridViewRow gvrowreport = lnkbtimage.NamingContainer as GridViewRow;
        //int Exhid = Convert.ToInt32(gvrowreport.Cells[1].Text);
        string Exhid = ((HiddenField)gvrowreport.Cells[0].FindControl("HiddenField1")).Value;
        SqlCommand cmd = new SqlCommand("select ImageName,ImageData from CompanyImage where Edition_Id='" + Session["Edition_ID"].ToString() + "' and Exhibitor_ID=@Exhibitor_ID ", con);
        cmd.Parameters.AddWithValue("@Exhibitor_ID", Exhid);
        //Select Statement con
        if (con.State == ConnectionState.Closed)
        {
            con.Open();
        }

        SqlDataReader dr = cmd.ExecuteReader();


        if (dr!=null)
        {
            dr.Read();
            LinkButton lnkbtn = sender as LinkButton;
            GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
            //string filePath = GridViewLogo.DataKeys[gvrow.RowIndex].Value.ToString();
            //if (!Convert.IsDBNull(dr["ImageData"]))
            //{
                Response.ContentType = "application/vnd.ms-jpg";
                //to open file prompt Box open or Save file
                Response.AddHeader("content-disposition", "attachment;filename=" + dr["ImageName"].ToString());
                Response.Charset = "";
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                Response.BinaryWrite((byte[])dr["ImageData"]);
                Response.End();
            //}
            //else
            //{
            //    //lblhid.Text = "Image is not uploaded here !!";
            //    //lblhid.ForeColor = Color.Green;
            //    //lblhid.Visible = true;
            //    //// lblhexcelerror.Visible = false;
            //    //gvrow.Visible = false;
            //}

        }

        else
        {
            //LinkButton lnkbtn = sender as LinkButton;
            //GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
            //gvrow.Visible = false;
        }

        con.Close(); 

With a few specific exceptions (eg forms with CSRF tokens) it's usually the case that when you click on a link the server doesn't care how you got there, it receives the request and serves the requested page or resource. 除了一些特定的例外情况(例如带有CSRF令牌的表单),通常情况是,当您单击链接时,服务器不在乎您如何到达那里,它会接收请求并提供请求的页面或资源。 It doesn't really know whether the link was contained within an Excel file, or another HTML document, an email etc. That's one of the clever things about hyperlinks, in fact. 它真的不知道链接是包含在Excel文件中,还是包含在另一个HTML文档,电子邮件中。实际上,这是有关超链接的聪明的事情之一。

Even if what you were suggesting was feasible, there would be nothing to stop a user from copying and pasting it into their browser and accessing it from there. 即使您所建议的是可行的,也没有什么可以阻止用户将其复制并粘贴到他们的浏览器中并从那里访问它。

If you don't want this link to work from your Excel document, and/or you don't want users to be given the link, the simplest thing would be not to include it in the document in the first place. 如果您不希望此链接在您的Excel文档中起作用,并且/或者您不希望为用户提供该链接,那么最简单的事情就是首先不要将其包含在文档中。

Also if it's the case that this link is being given to users who shouldn't have access to whatever is shown the link, then simply not giving them the link ("security by obscurity") is not really adequate protection. 同样,如果是这种链接被授予不应访问该链接所显示内容的用户,那么仅仅不给他们链接(“默默无闻的安全性”)实际上并不能提供足够的保护。 If that's the situation then you need to think about how access to that link is authorised, no matter where the user acquired the knowledge of it. 如果是这种情况,那么无论用户从何处获得对该链接的了解,都需要考虑如何授权访问该链接。

use trim in code of reports. 在报表代码中使用修剪。 In trim you have to remove "mailto:" while exporting it to the excel 在修剪中,您必须在将“ mailto:”导出到Excel时将其删除

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM