[RESOLVED]C# Razor (Webmatrix) => Request.Unvalidate not working

Need to store html code from textarea in a database (page is for internal use only).

Unfortunately string Text = Request.Unvalidated().Form["foo"] is not working.

string Text = Request.Unvalidated().Form["foo"];

<httpRuntime
      executionTimeout="5000"
      requestValidationMode="2.0"/>

Language: C# Razor (Webmatrix)

Appreciate all kind of hints!

gesund100

is not working

What does "not working" mean?

"is not working" means in detail:

If the "foo" textarea contains characters only the request…foo carries the value as expected.

If the foo textarea contains a "<" (opening bracket as used in <ul> or <li>) the cshtml page stops processing immediately and i am left with a blank website

(<html><head></head><body></body></html>).

PS: Spent a lot of time on your Mikesdottnetting websites, thanks for all the information provided there!

You shouldn’t need to change the requestValidationMode in your web.config file. I would remove that setting and simply use 

var input = Request.Unvalidated("foo");

thanks, deleted the "requestValidationMode"-part from web.config.

More information on the behaviour after more trial and error:

If i enter "< br>" (with whitespace after "<" -bracket): request…foo catches the value as expected.

If i enter "<br>" (without whitespace): request…foo doesn’t carry anything and the page stops processing as described before.

Another trick?

Do you have some kind of global error handling deployed? If so, can you disable it and try? You should at least be getting an HttpException. Or can you provide the least amount of code required to reproduce the issue?

Hello,

use ckeditor to enter information with html.

http://ckeditor.com/

Good morning!

# Entry "<br>" or "<ul>" causes the issue.

# Maxlength="2000" characters.

# There is no HttpExcetpion but an empty screen => containing no content at all.

Global error handling is left "as provided" with the StarterSite. 

Seems that validation is still preventing the cshtml page to process the unvalidated statement. 

This is the minimum code to cause the issue:

Test.cshtml
<
form name="neu" action="Test2?id=121" method="post" style="border: 0;margin: 0;padding: 0;"> <textarea name="wert" style="width: 650pt;height: 200pt;font-size: 11pt;">Please put break-test in here</textarea> <input type="submit" value="Speichern" style="padding: 3pt;height: 25pt;vertical-align: top;"> </form>
Test2.cshtml

@{ string id = Request.Params["id"]; string wert = Request.Unvalidated("wert"); }

<span>@wert</span>

I see the issue – you are posting to another page. Looks like there might be a bug in the Web Pages framework. It shouldn’t stop processing like that. It works as expected if you post the form to the same page that the form is in (which is the recommended
way to do things).

So sorry, but if i use recommended one (as written below) the issue is still there. Aaargh!

test1.cshtml

@
if(IsPost){ string id = Request.Params["id"]; string wert = Request.Unvalidated("wert"); <span>@wert</span> } <form action="?id=121" method="post" style="border: 0;margin: 0;padding: 0;"> <textarea name="wert" style="width: 650pt;height: 200pt;font-size: 11pt;">Please put break-test in here</textarea> <input type="submit" value="Speichern" style="padding: 3pt;height: 25pt;vertical-align: top;"> </form>

It seems that the issue only occurs if you use Request.Params to reference a Request value. If you simply use Request["id"] instead of Request.Params["id"], the page processes correctly whether you post to itself or to page2.cshtml.

Yeesss – thank you so much for saving my day!

By the way: using the Request.Form tag fails either.

Leave a Reply