ASP.NET Ajax文件上传控件无法与URL重写一起使用

fc123

我有一个来自asp.net Ajax控件工具包的文件上传控件。我的Web应用程序正在使用URL重写。

我的ajax文件上传控件标记如下,

 <cc1:AsyncFileUpload Width="200px" ID="fu" runat="server" OnClientUploadError="uploadError"
                        OnClientUploadStarted="StartUpload" OnClientUploadComplete="UploadComplete" CompleteBackColor="Lime"
                        UploaderStyle="Modern" ErrorBackColor="Red" ThrobberID="Throbber" OnUploadedComplete="AsyncFileUpload1_UploadedComplete"
                        UploadingBackColor="#66CCFF" />

我在服务器上的事件(后面的代码)如下所示,

protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
    {
        string extension = Path.GetExtension(fu.PostedFile.FileName).ToLower();
        string fileType = null;

        switch (extension)
        {
            case ".gif":
                fileType = "image/gif";
                break;
            case ".jpg":
            case ".jpeg":
            case ".jpe":
                fileType = "image/jpeg";
                break;
            case ".png":
                fileType = "image/png";
                break;
            default:
                lblStatus.Text = "<br />Error - invalid file type.<br />";

                return;
        }

        System.Threading.Thread.Sleep(5000);
        //string q = Decrypt(Request.QueryString["pname"].ToString());
        string q = Request.QueryString["un"].ToString();
        string sql = "update AppUser set Pic=@pic where ProfileName='" + q + "'";
        SqlConnection con = new SqlConnection(constr);
        byte[] imageBytes = new byte[fu.PostedFile.InputStream.Length + 1];
        fu.PostedFile.InputStream.Read(imageBytes, 0, imageBytes.Length);
        SqlCommand cmd = new SqlCommand(sql, con);
        cmd.Parameters.AddWithValue("@pic", imageBytes);
        con.Open();
        int ret = cmd.ExecuteNonQuery();
        if (ret > 0) { }


    }

我的与ajax文件上传器相关的客户端事件如下,

function uploadError(sender, args) {
        document.getElementById('lblStatus').innerText = args.get_fileName(), "<span style='color:red;'>" + args.get_errorMessage() + "</span>";
    }

    function StartUpload(sender, args) {alert("en");

        document.getElementById('lblStatus').innerText = 'Uploading Started.';
    }

    function UploadComplete(sender, args) {
        var filename = args.get_fileName();
        var contentType = args.get_contentType();
        var text = "Size of " + filename + " is " + args.get_length() + " bytes";
        if (contentType.length > 0) {
            text += " and content type is '" + contentType + "'.";
        }
        document.getElementById('lblStatus').innerText = text;
    }

似乎出现的问题是ajax扩展文件上传控件无法与url重写一起使用。

我与global.asax中的url重写有关的代码如下,

  protected void Application_BeginRequest(object sender, EventArgs e)
    {

        string CurrentUrl = HttpContext.Current.Request.Url.AbsoluteUri;
        string[] s = CurrentUrl.Split('/');
        string ActionName = CurrentUrl.Split('/')[s.Length - 1];
        bool f = checkUserExist(ActionName);
        if (f == true)
        {
            CurrentUrl = HttpContext.Current.Request.Url.AbsoluteUri.ToLower();
            s = CurrentUrl.Split('/');
            ActionName = CurrentUrl.Split('/')[s.Length - 1];

        }
        string originalPath = HttpContext.Current.Request.Path.ToLower();

        if (ActionName.Contains("AsyncFileUploadID"))
        {
            //string str = ActionName.Replace("alikhan/",@"/Auth/profile.aspx");//http://localhost:59287/auth/profile.aspx
            //HttpContext.Current.RewritePath(originalPath.Replace(str, ActionName));
            //HttpContext.Current.RewritePath(originalPath.Replace("Auth/profile.aspx", "Auth/profile.aspx"));
            HttpContext.Current.RewritePath("/auth/profile.aspx");

        }
        else
        {
            //alikhan?AsyncFileUploadID=fu1&rnd=0728572010062635
            if (!(ActionName.Contains("aspx") || ActionName.Contains("net") || ActionName.Contains(".") || ActionName.Contains("ashx")))
            {


                if (originalPath.Contains("/" + ActionName))
                {
                    HttpContext.Current.RewritePath(originalPath.Replace("/" + ActionName, @"/Auth/profile.aspx?un=" + ActionName));
                    // HttpContext.Current.Response.Redirect(@"/Auth/profile.aspx?un=" + ActionName);

                }
            }
            else
            {

                if (!(ActionName.Contains("ashx") || ActionName.Contains("aspx")))
                {

                    // if (!ActionName.Contains("AsyncFileUploadID"))
                    {
                        try
                        {
                            HttpContext.Current.RewritePath(originalPath.Replace(ActionName, ActionName));
                        }
                        catch (Exception ex)
                        {// HttpContext.Current.RewritePath(originalPath.Replace("fp.aspx", "fp.aspx"));
                        }
                    }

                }
                //HttpContext.Current.Response.Redirect("fp.aspx",true);

            }
        }


    }

我该如何运作。如何在URL重写中使用Ajax文件上传控件?

任何帮助将不胜感激。

谢谢

fc123

我要做的就是更改

HttpContext.Current.RewritePath(string)

弦必须调整

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

jQuery ajax文件与输入文件一起上传到ASP.NET

来自分类Dev

jQuery ajax文件与所有表单数据一起上传到ASP.NET

来自分类Dev

jQuery无法与asp.net验证控件一起使用

来自分类Dev

iOS 8 / Safari 8无法与ASP.NET AJAX扩展一起使用

来自分类Dev

ASP.NET AJAX控件工具包文件上传

来自分类Dev

如何将RDLC报表与ASP.Net MVC中的ReportViewer控件一起使用?

来自分类Dev

ASP.NET无法与外部JavaScript文件一起很好地工作

来自分类Dev

ASP.NET 5(ASP.NET Core)-无法与IIS一起运行

来自分类Dev

在ASP.NET Core中将ValidateAntiForgeryToken属性与Unobtrusive Ajax插件一起使用

来自分类Dev

Asp.net URL重写

来自分类Dev

无法获得基本本地化以与ASP.NET 5一起使用

来自分类Dev

无法将动态类型与asp.net vnext核心一起使用

来自分类Dev

jQuery datepicker无法与asp.net中的母版一起使用

来自分类Dev

ASP.NET Web API CORS无法与AngularJS一起使用

来自分类Dev

AuthorizeAttribute无法与ASP.NET Core 3.1中的端点路由一起使用

来自分类Dev

Container.DisplayIndex无法与ASP.NET中的分页一起使用

来自分类Dev

ASP.NET MVC延迟加载无法与ICollection一起使用

来自分类Dev

ASP.Net控件选择文件(不上传)

来自分类Dev

ASP.Net控件选择文件(不上传)

来自分类Dev

ASP.NET MVC中的文件上传控件

来自分类Dev

ASP.NET 上传文件控件并显示等待消息

来自分类Dev

忽略AJAX请求的ASP.NET URL重写规则

来自分类Dev

asp.net Webforms捆绑和压缩不能与.net Framework 4.0一起使用

来自分类Dev

在另一页上输入asp.net文件(使用Ajax跨页脚本文件上传)

来自分类Dev

在Windows Azure上PUT和Delete无法与ASP.NET WebAPI和数据库一起使用

来自分类Dev

无法将AutoMapper.Mapper.Map方法与ASP.NET Core 3.0 Web API一起使用

来自分类Dev

在ASP.NET Core 3.x MVC中将nameof()与Url.Action()和异步方法一起使用

来自分类Dev

在ASP.NET 5中重写URL

来自分类Dev

ASP.NET MVC和Angularjs一起+ ASP.NET Web API

Related 相关文章

  1. 1

    jQuery ajax文件与输入文件一起上传到ASP.NET

  2. 2

    jQuery ajax文件与所有表单数据一起上传到ASP.NET

  3. 3

    jQuery无法与asp.net验证控件一起使用

  4. 4

    iOS 8 / Safari 8无法与ASP.NET AJAX扩展一起使用

  5. 5

    ASP.NET AJAX控件工具包文件上传

  6. 6

    如何将RDLC报表与ASP.Net MVC中的ReportViewer控件一起使用?

  7. 7

    ASP.NET无法与外部JavaScript文件一起很好地工作

  8. 8

    ASP.NET 5(ASP.NET Core)-无法与IIS一起运行

  9. 9

    在ASP.NET Core中将ValidateAntiForgeryToken属性与Unobtrusive Ajax插件一起使用

  10. 10

    Asp.net URL重写

  11. 11

    无法获得基本本地化以与ASP.NET 5一起使用

  12. 12

    无法将动态类型与asp.net vnext核心一起使用

  13. 13

    jQuery datepicker无法与asp.net中的母版一起使用

  14. 14

    ASP.NET Web API CORS无法与AngularJS一起使用

  15. 15

    AuthorizeAttribute无法与ASP.NET Core 3.1中的端点路由一起使用

  16. 16

    Container.DisplayIndex无法与ASP.NET中的分页一起使用

  17. 17

    ASP.NET MVC延迟加载无法与ICollection一起使用

  18. 18

    ASP.Net控件选择文件(不上传)

  19. 19

    ASP.Net控件选择文件(不上传)

  20. 20

    ASP.NET MVC中的文件上传控件

  21. 21

    ASP.NET 上传文件控件并显示等待消息

  22. 22

    忽略AJAX请求的ASP.NET URL重写规则

  23. 23

    asp.net Webforms捆绑和压缩不能与.net Framework 4.0一起使用

  24. 24

    在另一页上输入asp.net文件(使用Ajax跨页脚本文件上传)

  25. 25

    在Windows Azure上PUT和Delete无法与ASP.NET WebAPI和数据库一起使用

  26. 26

    无法将AutoMapper.Mapper.Map方法与ASP.NET Core 3.0 Web API一起使用

  27. 27

    在ASP.NET Core 3.x MVC中将nameof()与Url.Action()和异步方法一起使用

  28. 28

    在ASP.NET 5中重写URL

  29. 29

    ASP.NET MVC和Angularjs一起+ ASP.NET Web API

热门标签

归档