|
|
 Rank: Fanatic
Joined: 9/17/2007 Posts: 264 Location: London, UK.
|
The subject is a clue :) Is there a way I can get validating HTML 4.01 Strict code out of the ASP.NET Form control? This: Code:<?ASPNET_FORM> </?ASPNET_FORM> Becomes this: Code:<form method="post" action="/Default.aspx" id="ctl08"> <div> <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" /> <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" /> <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJOTkzNjk4NjQ4ZGSW//vm8qE3EKmz9+YWE/beROxzOA==" /> </div>
<script type="text/javascript"> //<![CDATA[ var theForm = document.forms['ctl08']; if (!theForm) { theForm = document.ctl08; } function __doPostBack(eventTarget, eventArgument) { if (!theForm.onsubmit || (theForm.onsubmit() != false)) { theForm.__EVENTTARGET.value = eventTarget; theForm.__EVENTARGUMENT.value = eventArgument; theForm.submit(); } } //]]> </script>
<script src="/WebResource.axd?d=tQB5OI0TBUD5inJ9sy4TRA2&t=633313318131189796" type="text/javascript"></script>
<script src="/ScriptResource.axd?d=shSJSZHD3dLa3Z6tnPsXcS9FHy68Spb8cvE-ZEC1AEoCuwLQbEMe2vg_cEZ3HUOMW2SEzkCW-nsBerCxORDb6g-OROmqPUjJo9MayqySLxM1&t=633256170228490039" type="text/javascript"></script> <script src="/ScriptResource.axd?d=shSJSZHD3dLa3Z6tnPsXcS9FHy68Spb8cvE-ZEC1AEoCuwLQbEMe2vg_cEZ3HUOMW2SEzkCW-nsBerCxORDb6q6n4gKYYcH0J9g7hHiavyxTr5GeDKRyUib8aKX43emA0&t=633256170228490039" type="text/javascript"></script><script type="text/javascript"> //<![CDATA[ Sys.WebForms.PageRequestManager._initialize('umbracoScriptManager', document.getElementById('ctl08')); Sys.WebForms.PageRequestManager.getInstance()._updateControls([], [], [], 90); //]]> </script> <script type="text/javascript"> //<![CDATA[ Sys.Application.initialize(); //]]> </script> </form> And that gives the following validation errors: Code:value of attribute "ID" invalid: "_" cannot start a name . <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
NET-enabling start-tag requires SHORTTAG YES . …me="__EVENTTARGET" id="__EVENTTARGET" value="" />
value of attribute "ID" invalid: "_" cannot start a name . <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
NET-enabling start-tag requires SHORTTAG YES . …ENTARGUMENT" id="__EVENTARGUMENT" value="" />
value of attribute "ID" invalid: "_" cannot start a name . …type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJOTkzNjk4NjQ4
NET-enabling start-tag requires SHORTTAG YES . …jQ4ZGSW//vm8qE3EKmz9+YWE/beROxzOA==" /> That's pants! Is there a fix or workaround one can implement to stop "_" starting IDs and "/>" ending elements? Richard
2 * 3 * 3 * 37 : The prime factorisation of The Beast.
|
|
 Rank: Addict
Joined: 7/19/2006 Posts: 649 Location: Preston, UK
|
Richard, You can try using the compliance filter i stuck it on codeplex url is http://www.codeplex.com/compfilter4umbraco/ it fixes your issue and then some. Regards Ismail
Level 2 certified. If it aint broke dont fix.
|
|
 Rank: Fanatic
Joined: 9/17/2007 Posts: 264 Location: London, UK.
|
I was getting excited there but then I saw:
- ASP.NET hidden form variables (_VIEWSTATE,_EVENTARGUMENT and __EVENTTARGET) are now wrapped in a div element.
ASP.NET 2.0 does that anyway. That's not my problem. I need the viewstate ID renamed from, say "_VIEWSTATE,_EVENTARGUMENT" to "VIEWSTATE,_EVENTARGUMENT". Then it will validate to HTML 4.01.
Richard
2 * 3 * 3 * 37 : The prime factorisation of The Beast.
|
|
 Rank: Addict
Joined: 7/19/2006 Posts: 649 Location: Preston, UK
|
Richard, On my company website http://www.iasb2b.com/ view source you will see Code: <meta name="RiverInteractive.ComplianceFilterTest" content="v2.0.50727" />
in the head tag to say its been cleaned using compliance filter. then furthen in the html Code: <div> <input type="hidden" name="__EVENTARGUMENT" id="EVENTARGUMENT" value="" /> </div> <div> <input type="hidden" name="__EVENTTARGET" id="EVENTTARGET" value="" /> </div>
please note ids have no underscore. We had to do a load of clean up to get sites through sitemorse which is very strict in html checking. Regards Ismail
Level 2 certified. If it aint broke dont fix.
|
|
 Rank: Fanatic
Joined: 9/17/2007 Posts: 264 Location: London, UK.
|
Oh man, you saved me now :)
I know it's not strictly necessary and the browsers will show the content regardless but if you're going to do something, do it well I say. I'll get stuck in with this tomorrow morning.
Thanks,
Richard
2 * 3 * 3 * 37 : The prime factorisation of The Beast.
|
|
 Rank: Fanatic
Joined: 9/17/2007 Posts: 264 Location: London, UK.
|
Ismail, I got it working (and it's very cool indeed!) but I don't want it spitting out XHTML! The whole point is to make the code HTML 4.01 Strict compliant...
All I want is the IDs taking care of, I didn't want the entire page messed with.
Is there no way to limit the effect in config? If not I guess I can take apart your code and just use the ID removal bit. Eek.
Richard
2 * 3 * 3 * 37 : The prime factorisation of The Beast.
|
|
 Rank: Addict
Joined: 7/19/2006 Posts: 649 Location: Preston, UK
|
Richard,
No you will have to hack the code take out all the bits you dont need and just leave in the ids bit.
Regards
Ismail
Level 2 certified. If it aint broke dont fix.
|
|
 Rank: Fanatic
Joined: 9/17/2007 Posts: 264 Location: London, UK.
|
Wow, what an epic this is turning out to be! I think this might be of interest to people, so I'll post lots of code... After quite a lot of web research, I created a class library called IdFilter. There's two files there: 1 - IdFilterModule.csCode:using System; using System.Web;
namespace Company.Utilities { public class IdFilterModule : IHttpModule { public void Dispose() { } public void Init(HttpApplication app) { app.ReleaseRequestState += new EventHandler(InstallResponseFilter); } private void InstallResponseFilter(object sender, EventArgs e) { HttpResponse response = HttpContext.Current.Response;
if (response.ContentType == "text/html") { response.Filter = new IdFilter(response.Filter); } } } } 2 - IdFilter.csCode:using System; using System.Text; using System.Text.RegularExpressions; using System.IO; using System.Web;
namespace Company.Utilities { public class IdFilter : Stream { Stream responseStream; StringBuilder responseHtml; long position;
public IdFilter(Stream inputStream) { responseStream = inputStream; responseHtml = new StringBuilder(); }
public override bool CanRead { get { return true; } } public override bool CanSeek { get { return true; } } public override bool CanWrite { get { return true; } } public override void Close() { responseStream.Close(); } public override void Flush() { responseStream.Flush(); } public override long Length { get { return 0; } } public override long Position { get { return position; } set { position = value; } } public override long Seek(long offset, SeekOrigin origin) { return responseStream.Seek(offset, origin); } public override void SetLength(long length) { responseStream.SetLength(length); } public override int Read(byte[] buffer, int offset, int count) { return responseStream.Read(buffer, offset, count); } public override void Write(byte[] buffer, int offset, int count) { string strBuffer = System.Text.UTF8Encoding.UTF8.GetString(buffer, offset, count);
Regex eof = new Regex("</html>", RegexOptions.IgnoreCase);
if (!eof.IsMatch(strBuffer)) { responseHtml.Append(strBuffer); } else { responseHtml.Append(strBuffer);
string finalHtml = responseHtml.ToString();
finalHtml = finalHtml.Replace("id=\"__VIEWSTATE\"", "id=\"VIEWSTATE\""); finalHtml = finalHtml.Replace("id=\"__EVENTARGUMENT\"", "id=\"\"EVENTARGUMENT"); finalHtml = finalHtml.Replace("id=\"\"__EVENTTARGET", "id=\"\"EVENTTARGET"); finalHtml = finalHtml.Replace(" />", ">"); finalHtml = finalHtml.Replace(" />", ">"); finalHtml = finalHtml.Replace("/>", ">");
byte[] data = System.Text.UTF8Encoding.UTF8.GetBytes(finalHtml);
responseStream.Write(data, 0, data.Length); } } } } Yup, it really is that horrible :) Building that project gives me a .dll I can copy to bin and then reference in web.config as follows: Code:<httpModules> <add name="IdFilterModule" type="Company.Utilities.IdFilterModule, IdFilter" /> </httpModules> I created a test website project, incorporated the dll, set web.config and hey presto! My IDs were back to normal with underscores removed. But when I copied this over to my umbraco site I was disheartened to see that there was no effect :( I wonder if there is a glaring silly error on my part I need to address? I don't mind looking stupid if the fix is a 30-second one ;) Any ideas why it works in a normal website but not in umbraco? Richard
2 * 3 * 3 * 37 : The prime factorisation of The Beast.
|
|
 Rank: Addict
Joined: 7/19/2006 Posts: 649 Location: Preston, UK
|
Richard,
Trying running locally on your machine and in your project set a break point. Compile then dump the dll and pdb to your bin then attach to asp.net worker process via visual studio then hit page and see if it runs the module and if any errors are generated. Might also be worth putting a comment into your html before the end body to say clean by filter or something to that effect just to see if the filter is even running.
Regards
Ismail
Level 2 certified. If it aint broke dont fix.
|
|
|
Guest |