I'd like to have a classic ASP page that works similar to a jsfiddle except for VBscript this time. In other words, I need to display the output of vbscript code that is passed from one form to a page using POST.
Obviously, response.write(request.form()) doesn't work and I don't even know how if it's possible. I can see how a script could write the form input into a separate .asp page (using filesystemobject and writeline) which is then loaded, but is there a more elegant way as to not have a temporary page for each request?
You can do this using the execute() function (not to be confused with server.execute()).
Here is an example:
<%
if request.QueryString("task") = "execute" then
Response.Write "Output: <hr />"
Execute(Request.Form("VbScript"))
Response.Write "<hr />"
end if
%>
<form action="test.asp?task=execute" method="post">
<textarea name="VbScript" style="height: 100px">
x = 4 - 3
response.write x
</textarea>
<input type="submit" value="Execute" />
</form>
However, whilst this is fun, i cant think of a single use where security wouldnt be a major concern.
Your essentially giving the user full access to your server!
Related
I try to move my text analyzer from console to web form.
I have simple form like this:
<form action="/">
<textarea name="str"></textarea>
<input type="submit">
</form>
Generally I could have very long texts for analysis inside of textarea. When I submit the form I get the following from thin:
Invalid request: Header longer than allowed
So the question is what is the proper approach to send long texts to server? Uploading files or filling links to url are not the option unfortunately.
By default the method of a form is GET, which has a limit on the number of characters allowed. (The limit depends on server and client, see for instance this answer, which specifies that usually it is 8KB).
You should use instead a method POST, which has much larger limit, around 2GB.
<form action="/" method="POST">
<textarea name="str"></textarea>
<input type="submit">
</form>
Hy
What i want to do is to create a custom renderer for will_paginate which renders first, previous, next and last page and a input field where the user can type in the page number manually. I already have the links for first, last etc. but i stuck at the input field. I could create a form in the view but the input field has to be rendered between the previous and next links.
Does anyone know how to do this?
Thanks for your help
You can do this as a separate form (make sure it is a GET). All you
need is the one input element named page. Something as simple as this
should work (not all browsers may like the #). I dropped it into a
site I'm playing with now and it worked. Put it anywhere on your page.
You might have to make something more complicated if you need to
incorporate search terms.
<form action="#" method="get">
Go to page: <input type="text" name="page" value="" size="2"
maxlength="4" />
<input type="submit" name="btnSubmit" />
</form>
I have the following mark up in an ASP.NET MVC view (this is a Twitter Bootstrap search box):
<form action="#Url.Action("Results", "Search")" method="post">
<input type="text" class="search-query" id="SearchTerm" name="SearchTerm" />
</form>
This code works as expected, but using a post here is causing problems.
How can I change this markup to pass the search query as a URL argument instead? I'm not really sure how to even approach this short of keeping the existing markup and then redirecting from the controller. I'm thinking there must be a more efficient way than that.
You should be able to change method="post" to method="get" and get the desired result. The form, with a get method setting, pushes the fields in the form to the querystring by its default behavior.
As a workaround, if the default behavior doesn't suit you, you could catch the submit event of the form, and do:
window.location = form.action + "?SearchTerm=" + document.getElementById("SearchTerm").value
Something like that, where form is a reference to the form element. You can build the link and redirect using javascript, which is a get request.
I need to open another site in new tab from code behind in Asp.net MVC.
return Redirect("Url"); is used to open the another site within the same tab.
It doesn't really seem practical for the users, because after authenticating in the second tab, they have to refresh the first tab to see the effects.
The ReturnUrl property of FormsAuthentication seems to do what you want. When the user needs to log in, they are redirected to the login page, and after signing in they are redirected back.
If you are making extensive use of javascript and ajax, and want to keep the javascript variables of the current page but need to log in to do the ajax calls, there might be another solution. If the response of your ajax call is the unauthenticated header, open a lightbox or something like that with a username and password field. Use ajax post to the AccountController to sign in the user again. This way, the user is authenticated again, but you keep the javascript variables.
This can be done using javascript only. Try this.
<%
Response.Write '<script type="text/javascript">
window.open(url);
</script>'
%>
Hope it works.
if you call action from form and use input type of submit you can try
<input type="submit" formtarget="_blank" />
if you use link <a> or AjaxCall you can try
<a target="_blank"></a> or in ajax helper set property #target="_blank"
here is my code
cshtml
#using (Html.BeginForm("PersonsReport", "Reports"))
{
<br />
<div style="text-align: center;">
<input type="submit" formtarget="_blank" class="btn btn-primary" value="GetReport" style="width:100%;" />
</div>
<br />
}
controller.cs
public ActionResult PersonsReport()
{
return Redirect("/PersonsReport.aspx");
}
I'm trying to add a search box to a master page in an ASP.Net MVC web app. What's confusing me is how to properly implement it in the master page. So the user types in data into this search box, how should the data be handled from an MVC perspective?? I know I could use he master page's code behind, but I shouldn't. I'm currently trying to use a user control for this, but I'm not sure how to properly implement it and online resources seem to be limited. Would creating an HTML helper be best??
To summarize: Implement a search box in the MVC master page that directs to a different website and includes the user's query that they typed in the search box.
Is it better to use:
Master Page's codebehind
A user control
Or create a separate HTML Helper.
UPDATE:
Ok, per queen3's advice, I implemented a SearchController and used the HTML Helper BeginForm to generate a search box.
Controller action:
Function SearchWiki(ByVal q As String) As ActionResult
Return Redirect("http://home/search/Results.aspx?k=" & q & "&s=IT%20FAQ")
End Function
And in the Master Page:
<% Using Html.BeginForm("SearchWiki", "Search", FormMethod.Post)%>
<input type="text" name="q" />
<input type="submit" value="Search" />
<% End Using%>
But when I try to debug, the SearchWiki function never gets called and, as a result, nothing happens when I type in the search box and hit Search.
Forget about codebehind and user controls if you're going to use ASP.NET MVC. You need HTML, CSS, and JavaScript.
I suppose you want something like
<form action="<%= Url.Action("Index", "Search") %>" method="post">
<input type="text" name="q" />
</form>
With helpers it will be something like
<% Html.BeginForm("Index", "Search") %>
<input type="text" name="q" />
<% Html.EndForm() %>
Just put this into master page where appropriate in you site design. Then create SearchController to handle request, and return View() with search results. You may make form use GET instead of POST if you accept google-like search requests /Search?q=text.
The controller is very simple:
public class SearchController: Controller
{
public ActionResult Index(string q)
{
return View(SearchHelper.DoSearch(q));
// or return Redirect("http://site?q=" + q) if you want redirect
}
}
To summarize: Implement a search box
in the MVC master page that directs to
a different website and includes the
user's query that they typed in the
search box.
Seems like you want to use a different search provider. In this case you don't need any server-sided code at all... only pure html. I'll give you an example with Google:
<form id="search" action="http://www.google.com.br/search" method="GET">
<input type="text" name="q" />
<input type="submit" value="Submit" />
</form>
Just add this code on your MasterPage and we're done.
You can also add some JQuery to append the string "site:www.yoursite.com" to the search query. Doing so you can ask google to search the keywords on your site. The javascript code should be:
$("#search").submit(function(){
var input = $(this).find('input[name=q]');
var query = input.val() + ' site:www.yoursite.com';
input.val(query);
});