Bad Request (invalid url) when POSTing

Last post 03-06-2009, 12:08 PM by nkingmnwd. 2 replies.
Sort Posts: Previous Next
  •  03-06-2009, 10:54 AM 49571

    Bad Request (invalid url) when POSTing

     Hi!
    Im new, please dont beat me up :)
     
    Quite suddenly, i am getting a Bad Request (invalid url) when submitting changes with a POST. The editor control loads fine, and  otherwise functions as it should. We have a domain license, i am not getting license errors. Below is the url that is in the address bar when i get the Bad Request.
     
    http://www.mysite.com/admin/%3C%=Request.ServerVariables%5B%22SCRIPT_NAME%22%5D%%3E
     
    heres what i know:
     
    we upgraded the server to .net 3.5 framework, i am pretty sure thats when the script stopped working. I have since backrevved to 2.0 but that has not fixed the issue. I have also restored the admin area of my site from the original (working) package, so the admin scripts and cuteEdit files are from a known good source.
     
    permission have not changed on the server- perhaps sombody can verify for me the necessary permissions for  ASPNET machine account? currently ASPNET has full control on my content directories.
     
    I can provide any other details on my config as needed.
     
    TIA for your help!
     
    here is the code of my edit-page.aspx. the default.aspx is the page that users choose what page they are editing- it calls the edit page and is working fine. 
     
    <%@ Page Language="C#" validateRequest="false" Debug="true" %>
    <%@ Import Namespace="System" %>
    <%@ Import Namespace="System.IO" %>
    <%@ Import Namespace="System.Web" %>
    <%@ Import Namespace="System.Net" %>
    <%@ Import Namespace="System.Web.UI" %>
    <%@ Import Namespace="System.Xml" %>
    <%@ Import Namespace="System.Collections" %>
    <%@ Import Namespace="System.Collections.Specialized" %>
    <%@ Import Namespace="SilverTech.FormCode" %>

    <%@ Register TagPrefix="CE" Namespace="CuteEditor" Assembly="CuteEditor" %>
    <%@ Register TagPrefix="Website" TagName="Header" src="http://cutesoft.net/admin/common/admin-header.ascx" %>
    <%@ Register TagPrefix="Website" TagName="Footer" src="http://cutesoft.net/admin/common/admin-footer.ascx" %>

    <script runat='server' language='C#'>
    FieldCollection coll = null;
    bool bValidated = true;
    string fileName = "";
    string memoName = "";
    string configName = "";

    public new bool IsPostBack {
        get {
            return base.IsPostBack || Request.ServerVariables["request_method"] == "POST";
        }
    }

    void Page_Load(System.Object sender, System.EventArgs e) {
        string text = "";
        
        if( Request.QueryString["fn"] != null )
            fileName = Request.QueryString["fn"];
        if( Request.QueryString["mn"] != null )
            memoName = Request.QueryString["mn"];
        if( Request.QueryString["cn"] != null )
            configName = Request.QueryString["cn"];
        
        if( fileName.Length == 0 || memoName.Length == 0 || configName.Length == 0 )
            Response.Redirect("/admin/default.asp");
        
        
        Editor1.BreakElement = BreakElement.Br;
        Editor1.AutoConfigure = AutoConfigure.Simple;
        
        initializeForm();
        if (IsPostBack) {
            coll.load(Request.Form);
            
            if( Editor1.Text.Length > 0 ) {
                text = Editor1.Text;
                //text = text.Replace(Request.ServerVariables["SERVER_NAME"], "");
                text = text.Replace("/admin/", "");
                coll["text"].fldValue = text;
            }

            if( !coll.inError() ) {         
                saveData();
                Response.Redirect("/admin/default.aspx");
            }
            else
                bValidated = false;
        }
        else
            loadData();
    }

    void initializeForm() {        
        coll = new FieldCollection(Server, Response);
        
        coll.add(new MemoField("text", memoName, true, 64000));
    }

    void saveData() {
        if( coll["text"].fldValue.Length > 0 ) {
            string path = Application[configName].ToString();
            if( path.Length > 0 ) {
                string folderPath = Server.MapPath(path);
                if( Directory.Exists(folderPath) )    {
                    string filePath = folderPath + fileName;            
                    
                    if( File.Exists(filePath) )
                        File.Delete(filePath);
                    StreamWriter sw = new StreamWriter(filePath);
                    sw.Write(coll["text"].fldValue);
                    sw.Close();                    
                }
            }
        }
    }

    void loadData() {
        string path = Application[configName].ToString();
        if( path.Length > 0 ) {
            string folderPath = Server.MapPath(path);
            if( Directory.Exists(folderPath) ) {
                string filePath = folderPath + fileName;
                if( File.Exists(filePath) )  {
                    StringBuilder buff = new StringBuilder();
                    StreamReader sr = new StreamReader(filePath) ;
                    string line;
                    
                    while ((line = sr.ReadLine()) != null) {
                        buff.Append(line);
                        buff.Append(""n");
                    }
                    sr.Close();
                    Editor1.Text = buff.ToString();
                }
            }
        }
    }

    void showField(string fldname) {
        Response.Write("<tr>");
        showFieldTitle(coll[fldname].displayName, coll[fldname].required);
        Response.Write("</tr>");
        Response.Write("<tr>");
        Response.Write("<td class='copy' colspan='2'>");
        coll.createField(fldname, "ip");
        Response.Write("</td>");
        Response.Write("</tr>");    

        if( coll.inError(fldname) ) {
            Response.Write("<tr>");
            Response.Write("<td colspan='2' class='errmsg'>");
            Response.Write(coll.getErrorMsg(fldname));
            Response.Write("</td>");
            Response.Write("</tr>");
        }
    }

    void showFieldTitle(string title, bool required) {
        Response.Write("<td class='copy' colspan='2'>");
        if( required )
            Response.Write("<span class='errmsg'>*</span>");
        Response.Write("<nobr>" + title + "</nobr>");
        Response.Write("</td>");
    }

    void showFields(string[] flds) {
        foreach( string fld in flds ) {
            showField(fld);
        }
    }
    </script>

    <Website:Header id="header" runat="server" />
    <form name='inputForm' action='<%=Request.ServerVariables["SCRIPT_NAME"]%>' method='POST' runat='server'>
    <table border='0' cellpadding='2' cellspacing='2' width='100%' bgcolor='#ffffff'>
        <% if( !bValidated )
            Response.Write("<tr><td colspan='2' class='errmsg'>There were some errors while processing the form. Please scroll down and correct them.</td></tr>"n");
        %>
        <tr><td colspan='2' class='copy'>&nbsp;</td></tr>
        <tr><td colspan='2' class='copy'><p><b>Full screen mode button (<IMG class="CuteEditorButton" align=absmiddle title="Fit to Window - F12" src="http://cutesoft.net/CuteSoft_Client/CuteEditor/Themes/Custom/Images/fit.gif" /> F12 shortcut) allows you to stretch the Editor to the width and height of your browser window.</b></p></td></tr>
        <tr><td colspan='2' class='copy'>&nbsp;</td></tr>
        <tr><td colspan='2' class='copy'>Required form fields are marked by <span class='errmsg'>*</span></td></tr>    
        <%
    //    showFields(new string [] {"text"});
        showFieldTitle(coll["text"].displayName, coll["text"].required);
        %>
        <CE:Editor id="Editor1" EditorWysiwygModeCss="/library/styles/master.css" RemoveServerNamesFromUrl="true" runat="server"></CE:Editor>
        
        <tr><td colspan='2'>&nbsp;</td></tr>
    </table>
    <input type="submit" value="Submit" class='btn2'>
    </form>
    <Website:Footer id="footer" runat="server" />
  •  03-06-2009, 11:58 AM 49583 in reply to 49571

    Re: Bad Request (invalid url) when POSTing

    Is the '/%3C%=Request.ServerVariables%5B%22SCRIPT_NAME%22%5D%%3E' added by your code ?
     
    Or you visit the http://www.mysite.com/admin/ , and after postback , that string be added ?
     
    Regards,
    Terry
     
  •  03-06-2009, 12:08 PM 49584 in reply to 49583

    Re: Bad Request (invalid url) when POSTing

    thanks for the quick reply Terry-
     
    that is the url i see in my address bar after hitting the Submit button (doing the post)
     
    so, your second option :)
     
    in FFox, i get the bad request page- but i just noticed at that using IE i can hit the Submit and nothing happens!
     
    this is in the status bar when i hover the Submit button:
     
    <%=Request.ServerVariables%5B%22SCRIPT_NAME%>
     
    hope this helps...
     
View as RSS news feed in XML