VBS Not writing text to webpage - html

I have the following VBS code in my webpage:
<body>
<%
Randomize
response.write(Rnd)
%>
</body>
But instead of outputting a random number, I get a webpage that says this:
<% Randomize response.write(Rnd) %>
Why won't my code execute?
Thank you.

You need to make sure your webpage extension is managed by the ASP handler mapping. The steps to configure handler mappings depend on the version of IIS you are using.
See this page for information on configuring ASP under IIS 7 or 7.5.

Related

Rendering HTML using Embedded Code Blocks

I am looking at some older HTML in an .ascx file which has an embedded code block "<% Some Server Logic %>". I get that best practice is to control server logic on the server, for maintainability and debugging and.... I see that it is bad. Not my code I am just trying to understand why someone would put this in the code. Is it just old code that at the time was cutting edge and why it's implemented or is it just junk?
The code is testing a user's role and based on the role they then execute/render the HTML within the conditional statement. Does this prevent the HTML from rendering at all, or should it?
Here is a sample:
<% if (userRole.IsInRole("someRole") || userRole.IsInRole("AnotherRole")) { %>
<section id="someId">
<div>Some Html</div>
</section>
<% } %>

if page is default then include if not default then

I've read similar questions, but none seems working for me.
I have an asp site, i think classic (don't even know difference between classic and net), with few pages all with asp extension, and some html includes, one of these being a slider which I want to only display when in homepage (default.asp), and if not default then add a div to the markup.
I know the following is wrong, but just to better explain my need.
<%
if page == default.asp
include file="slider.html"
if page != default.asp
<div class="spacer-top"></div>
%>
Like many of your predecessors in ASP-classic-land, what you're wanting is conditional includes, and the problem you're bumping into is that classic ASP doesn't do conditional includes. (The reason why is that the #include directive is handled long before any script on the page is parsed.)
There are various workarounds involving Execute or other dangerous-in-the-wrong-hands commands; search for "asp conditional include" and you'll find more than you were bargaining for. However, in your case, it might be simpler to encase the slider display in a subroutine that you can call or not.
Slider.html:
<%
Sub DisplaySlider()
'code to display the slider (probably JavaScript, I'm guessing?)
%>
<script ...>
</script>
<%
End Sub
%>
Other pages:
<!-- #include virtual="/slider.html" -->
<%
scriptname = Request.ServerVariables("Script_Name")
If InStr(scriptname, "default.asp") > 0 Then
DisplaySlider
Else
Response.Write "<div class='spacer-top'></div>"
End If
%>
Martha is bang on the nail.
To augment her answer I feel I should point out that system design comes into play, here. Try keeping your modules small and succinct, targeting their functionality to a particular aspect of your application's requirements. For example:
one to deal with your data layer
one to deal with more advanced form handling
one to deal with blah
You get the idea.
Another idea is to include common functions in your global.asa so they're available to all modules within your application instantly.

Creating dynamic links for a HTML email with embedded ruby

I have a simple question about links in HTML emails
I am trying to add a simple dynamic link in an HTML email to my site like this
MySite
This fails, but this works
MySite
I am assuming its to do with the embedded ruby but strangely, the links work if I view them on my iphone.
Any thoughts on this?
Stupid me....
I needed to construct the link using the ActionMailer generating URLs instructions, see here http://guides.rubyonrails.org/action_mailer_basics.html#generating-urls-in-action-mailer-views
My URL is
<%= link_to "View response", notification_micropost_response_url(#micropost, #response) %>
The default host must be first set in the dev and prod environment config files:
Example (development.rb)
config.action_mailer.default_url_options = { :host => 'localhost:3000' }

Get Windows User name in ASP.NET HTML Page

I have an asp.net application and in that I have a html page.
I need to get the Windows username in that html page.
I understand its not possible in normal page.
I need to achieve this without using ActiveX objects.
you will need to create an AJAX call on your page to some WebMethod in your ASP.NET application that call will return you user name.
it basicaly comes down to placeing request to the WebMethod like this
the call below gets data from WebMothod and displays it in the div in the page
$.get('jqueryintro.htm', function (data) {
$('#maindiv').html(data);
});
If you will need more information you can use this page very easy to follow article.
And don't forget to include jQuery ($) in your page
Assuming you have Windows authentication enabled on the site and the user is authenticated you can put this in your ASPX:
<p><%= User.Identity.Name %></p>
The above code embeds the username in the HTML that is sent to the client.
An AJAX request is not required.
Try something like this...
<div runat="server"><%= System.Security.Principal.WindowsIdentity.GetCurrent().Name %></div>
<div runat="server"><%= User.Identity.Name %></div>
<div runat="server"><%= Request.ServerVariables["LOGON_USER"].ToString() %></div>
As long as you are using Windows Auth it should work, otherwise you would just get the account info for whatever IIS is running under.
Any container with runat="server" should work really it doesn't have to be a div.

output a variable in rails containing html code Ruby on Rails

I have a little problem with an output in ruby and rails.
I am still a beginner at rails, so it can be that the solution is pretty easy and i just can't see it.
I am trying to parse a website and put out some of the sourcecode on my own website.
Problem: it always puts out the whole source code as a text and is not interpreting the html code. how can i change that?
code:
page = Nokogiri::HTML(open("https://www.google.ch/search?client=ubuntu&channel=fs&q=google&ie=utf-8&oe=utf-8&redir_esc=&ei=WMpyUfSWEuz07AaTioCwDw"))
source = page.css('div#_css0')
<%= page %>
result:
http://postimg.org/image/dsaib9lx3/
I want to it to look like:
http://postimg.org/image/z9qlhoef5/
Thanks for any suggestions!
You should use raw in erb. It is actually equivalent to calling html_safe on it, but, just like h, is declared on a helper, so it can only be used on controllers and views.
page = Nokogiri::HTML(open("https://www.google.ch"))
<%= raw page %>
or
<%= raw Nokogiri::HTML(open("http://www.google.com")) %>
In Rails views every string content gets escaped, unless you use html_safe (docs)