my web page is running in chrome or not? - asp.net

How can i check whether the webpage is running in Chrome or not?
if not alert the user that you are not running in chrome:
the scenario will be like this:
IF webPage is not running in Firefox then
msgbox("You are not running in chrom")
End if
Can any one help me to do like this? am using Asp.Net with VB

You'll want to check the value of HttpRequest.UserAgent - the contents of this can vary wildly across browsers (here's a few examples), but in general a Chrome user agent will contain a part like Chrome/37.0.2062.124
So in your .aspx page, you could have something like this:
<% If Not HttpRequest.UserAgent.Contains("Chrome/") Then %>
<script type="text/javascript">alert("You are not using the Chrome browser");</script>
<% End If %>
(I put the <% %> in because this doesn't go in the .aspx.vb backend page)

Related

SilverStripe draft content status

Is there an easy way to identify draft content when viewing draft pages/content on my website? I want the ability to identify draft content and style it differently to published content.
I was hoping to find something like:
<% if $status == 'draft' %>
...
<% end_if %>
SilverStripe pages are stored in SiteTree and SiteTree_Live tables. The former table contains draft content (internally called as Stage stage), and the later contains published content (Live stage). SiteTree_versions table contains all modified versions of the page.
When you request a page in production, it is read from Live stage by default. When you see preview in the CMS you can switch between stages.
You can get Versioned reading stage as following
<% if $CurrentReadingMode = 'Stage.Stage' %>
Draft content
<% end_if %>
<% if $CurrentReadingMode = 'Stage.Live' %>
Published content
<% end_if %>
You might have a look at the https://github.com/jonom/silverstripe-betternavigator module which shows a nice red (draft) or green (live) status bar (and a handy menu for e.g. editing this page) in the right upper corner:
Just install it using composer and put $BetterNavigator somewhere in your template(s). If your website uses caching, make sure BetterNavigator's output is excluded.
You can also configure it so that it's just shown when you're in dev mode or logged in.
I normally use something like this to avoid showing it to everyone when I'm in dev mode:
<% if $CurrentUser %>
$BetterNavigator
<% end_if %>

displaying session value instead of code itself in aspx

<%= Session.Item("user_fullname")%>
this supposed to display session value right?
but mine is displaying code itself....
Note: I have included aspx page in another aspx, like:
<% Response.WriteFile("../etc/header1.aspx") %>
the displaing session code is inside header1.aspx
anyone knows how to display session value?
Session items would be stored as an Object. You need to cast to the correct type:
<%= (string)Session.Item("user_fullname") %>
When using Response.WriteFile("../etc/header1.aspx"), the usual Page Life cycle will NOT be executed for the mentioned header1.aspx page.
Since there will be no asp.net page life cycle processing , the inline code
<% %> won't be executed at all and therefore all such statements will be displayed as it is.
Response.WriteFile() is used to write just the Contents of a file, which can contain HTML , Controls, directly to the output stream.

accessing variables declared outside the asp code

<script ID="clientEventHandlersVBS" LANGUAGE="vbscript">
s=pass()
y=s
</script>
<%
session("password")=y
Response.write(session("password"))
Response.write(y)
%>
i have this code. but nothing is getting stored inside the session variable neither anything is getting printed. cant i access the variables declared outside the asp code or is their any syntax mistake. any help is really appreciated
First of all put
<% Option Explicit %>
at the top of every .asp page.
You will immediatly see that you are trying to access non declared variabels s and y.
So of course nothing is stored in the session variables.
Can you not use
<%
s = pass
y = s
%>
and so on ?
What is the purpose of the <script ... line if you are using vbscript any how ?
As implied by the ID of the script (clientEventHandlersVBS) the code contained in there refers to the client (the browser, IE in this case since it is the only one that supports VB client-side)
the <% %> tags though refer to server side ASP code..
These two can never communicate as they happen at different times/computers...

What is the practical difference between Response.Write and <%= %>?

I've run into an issue where a third-party component appears to be interfering with Response.Write and causing any content within Response.Write("") to render before any of the other html. For example:
<html><head><title><% Response.Write("HELLO WORLD") %>
will render as
HELLO WORLD<html><head>...
However, any content rendered using <%= %> blocks will work correctly. The below code will work perfectly:
<html><head><title><%="HELLO WORLD"%>
I always assumed that <%= was simply shorthand for Response.Write. From what I've been able to find on MSDN I now understand that it <%= is eventually converted to Response.Write, but apparently there are a few steps inbetween.
Does anyone have a guess as to why the two would render differently or point me to some documentation/info that explains how <%= %> blocks are handled?
Update: The control that was causing the issue was the Telerik AjaxManager control from the 2009 Q1 release. Upgrading to the Q2 control resolved the problem.
Unfortunately I don't have access to the source so I haven't been able to figure out why the control was causing this behavior. The issue has been resolved but I am still very curious as to why it existed in the first place.
<%= "foo" %> is turned into Response.Write("foo"); once it is compiled. You can verify this by digging through the ASP.NET Temporary Files folder and using Reflector to decompile the dll's you find.

How do i get rid of __o is not declared?

I have some code in my master page that sets up a a hyperlink with some context sensitive information
<%If Not IsNothing(Profile.ClientID) Then%>
<span class="menu-nav">
<a target="_blank"
href=
"http://b/x.aspx?ClientID=<%=Profile.ClientID.ToString()%>&Initials=<%=Session("Initials")%>"
>
Send
<br />
SMS
<br />
</a>
</span>
<%End If %>
<span class="menu-nav"> <!-- Name __o is not declared Error is flagged here-->
Now the issue seems to be in the href part. If I remove the dynamic code the error disappears. Can anyone tell me how to resolve this issue?
I've found the answer on the .net forums. It contains a good explanation of why ASP.Net is acting the way it is:
We have finally obtained reliable repro and identified the underlying issue. A trivial repro looks like this:
<% if (true) { %>
<%=1%>
<% } %>
<%=2%>
In order to provide intellisense in <%= %> blocks at design time, ASP.NET generates assignment to a temporary __o variable and language (VB or C#) then provide the intellisense for the variable. That is done when page compiler sees the first <%= ... %> block. But here, the block is inside the if, so after the if closes, the variable goes out of scope. We end up generating something like this:
if (true) {
object #__o;
#__o = 1;
}
#__o = 2;
The workaround is to add a dummy expression early in the page. E.g. <%="" %>. This will not render anything, and it will make sure that __o is declared top level in the Render method, before any potential ‘if’ (or other scoping) statement.
An alternative solution is to simply use
<% response.write(var) %>
instead of
<%= var %>
Yes, I have experienced the same bug occasionally in pages that use server side constructs on ASPX pages.
Overtime, I found a fix for it (I'm sorry, I just haven't been able to find out where I found this bit of info again.) and that fix is to put the following code above the errant <%...%> block:
<%-- For other devs: Do not remove below line. --%>
<%="" %>
<%-- For other devs: Do not remove above line. --%>
Apparently, where you put the above code makes all the difference to VS.NET, so it may take a few tries to get it right.
This is an odd solution, but for me I managed to fix this problem by simply closing the offending open files in Visual Studio.
With them open, i was erratically getting the __o problem.
As soon as I closed them, the __o problem disappeared.
After some hours of googling and analyzing bunch of aspx'ses in my current project seems I've found the solution, that is working for me. Would to advise strongly avoid html-style comments:
<!-- ... -->
inside aspx page. Instead of it use aspx-style comments
<%-- ... --%>
Additionally it helped me obtain that vs intellisense and code highlighting became working again and the mainly thing - this case had begun from it - vs can now hit the breakpoints inside embedded pieces of vb/cs code! And no any damn "This is not a valid location for a breakpoint" message.
When I've cleaned the solution, restarted IIS and it is still mysteriously playing up, I find this can sometimes be caused by pasting an ASPX source file's contents from another system into Visual Studio which "helpfully" updates the code, possibly changing some IDs and breaking the page.
Pasting it into another editor (Notepad++?) then saving it stops Visual Studio from "being helpful" and the page works again.

Resources