Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在响应扩展中注册脚本?_C#_Ajax - Fatal编程技术网

C# 如何在响应扩展中注册脚本?

C# 如何在响应扩展中注册脚本?,c#,ajax,C#,Ajax,我有一个HttpResponseExtensions类,它扩展了HttpResponse的功能。我想在AJAX请求中添加一个重定向用户的方法。下面是我进行检查的方法: public static void RedirectUser(this HttpResponse response, string url) { if (response.IsRequestBeingRedirecting()) return; var co

我有一个HttpResponseExtensions类,它扩展了HttpResponse的功能。我想在AJAX请求中添加一个重定向用户的方法。下面是我进行检查的方法:

    public static void RedirectUser(this HttpResponse response, string url)
    {
        if (response.IsRequestBeingRedirecting())
            return;
        var context = HttpContext.Current;
        if (context != null)
        {
            context.ApplicationInstance.CompleteRequest();
        }
        if (context != null && context.Request.IsAjaxRequest())
        {
            context.Items["IsRedirecting"] = true;
            RegisterRedirectScript(response,url);
        }
        else
        {
            response.Redirect(url, false);
        }
    }
下面是RegisterRedirectScript方法的实现

    public static void RegisterRedirectScript(this HttpResponse response, string url)
    {
        var context = HttpContext.Current;
        if (context != null)
        {
            context.Response.Write(string.Format("<script                       type='text/javascript'>window.location.href = '{0}';</script>", url));
        }
    } 
我知道我可以使用radAjaxManager、ClientScriptManager或ScriptManager注册脚本。但是我怎样才能为HttpResponse类做到这一点呢

感谢您的帮助

The Message recived from the server could not be parsed. Common causes for this error are the response is modified calls to response.write(), response details , HttpModule, OR server trace is enabled. Error detailes next to : window.locat.