locked
C# Razor (Webmatrix) => Request.Unvalidate not working RRS feed

  • Question

  • User927760811 posted

    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!

    Monday, November 10, 2014 10:45 AM

Answers

  • User-821857111 posted

    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 11, 2014 4:53 AM

All replies

  • User-821857111 posted

    is not working

    What does "not working" mean?

    Monday, November 10, 2014 10:49 AM
  • User927760811 posted

    "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!

    Monday, November 10, 2014 11:08 AM
  • User-821857111 posted

    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");
    Monday, November 10, 2014 11:27 AM
  • User927760811 posted

    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?

    Monday, November 10, 2014 12:12 PM
  • User-821857111 posted

    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?

    Monday, November 10, 2014 2:20 PM
  • User-735851359 posted

    Hello,

    use ckeditor to enter information with html.

    http://ckeditor.com/

    Monday, November 10, 2014 3:04 PM
  • User927760811 posted

    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>

    Tuesday, November 11, 2014 3:28 AM
  • User-821857111 posted

    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).

    Tuesday, November 11, 2014 4:10 AM
  • User927760811 posted

    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>
    Tuesday, November 11, 2014 4:30 AM
  • User-821857111 posted

    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 11, 2014 4:53 AM
  • User927760811 posted

    Yeesss - thank you so much for saving my day!

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

    Tuesday, November 11, 2014 5:23 AM