How to exclude some content from _LyoutView being added to specific view - asp.net-mvc-3

I have such script on my _LyoutView:
<noscript>
<meta http-equiv="refresh" content="0; URL=/Noscript">
</noscript>
But when user with javascript disabled redirected to that page, the infinity request of that page taking place because that page contains this code above as well.
So i just thought may be there is some things out of the box in ASP.NET MVC that can help?
Basically i want that that code from _LyoutView to be added to all views except Noscript view.
i can go like that on _LyoutView:
#if (ViewContext.Controller.ValueProvider.GetValue("action").RawValue != "Noscript")
{
<noscript>
<meta http-equiv="refresh" content="0; URL=/Noscript">
</noscript>
}
But may be there is more better way of doing that?

You can check the RawUrl property of the Request object to see if it contains the term "Noscript" which I'm assuming won't be part of the URL unless we're on that page.
#if(!Request.RawUrl.Contains("Noscript"))
{
<noscript>
<meta http-equiv="refresh" content="0; URL=/Noscript">
</noscript>
}

Related

Domain redirection and url masking

The image uploaded shows the post preview thumbnail of facebook.
(1)Consider a link x.com/abc which is redirected to y.com/xyz.
(2)When the link x.com/abc is shared on facebook it's preview is fetched from y.com/xyz.
(3)The preview thumbnail generated by facebook contains the domain y.com and not the x.com.
(4)How do we make the preview thumbnail show x.com and not the target url y.com.
The facebook screenshot show's that I shared url hivirality.com/abhishek which is redirected on citryxsolutions.in but the preview thumbnail contains the domain name of targeted url i.e citryxsolutions.in.
What are the possible cases to fix the issue.
You can do that, but it is a bit tricky. Instead of 301 redirect from x.com/abc to y.com/xyz. Your server should return HTML, which will redirect user through JS. This HTML should have Open Graph markup which Facebook is parsing. For example:
<!doctype html>
<html lang='en'>
<head>
<meta charset="utf-8" />
<meta property="og:url" content="URL" />
<meta property="og:title" content="TITLE" />
<meta property="og:type" content="website" />
<meta property="og:description" content="DESCRIPTION" />
<meta property="og:image" content="IMAGE URL" />
</head>
<body>
<script type="text/javascript">
if("false" == "false") {
window.location = "DESTINATION URL";
}
</script>
</body>
</html>
Where URL is x.com/abc
And DESTINATION URL is y.com/xyz
And you can check how Facebook reacts on that in FB debugger (also you can clear cache here): https://developers.facebook.com/tools/debug/

jQuery mobile "pageinit" calls hashtag for short time

I'm currently building a page with jQuery mobile.
I need to load some custon JavaScript on one page, so I found the pageInit function.
Here's a short example of what i'm using:
page1.html:
<!doctype html>
<meta charset="uft-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>page1 | test page for jquery mobile</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css">
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
<script src="js.js"></script>
<div data-role="page" id="page1">
<div data-role="header">
<h1>Page 1 Title</h1>
</div>
<div data-role="content">
go to page2
<p>Page 1 content goes here.</p>
</div>
<div data-role="footer">
<h4>Page 1 Footer</h4>
</div>
</div>
page2.html:
<!doctype html>
<meta charset="uft-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>page1 | test page for jquery mobile</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css">
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
<script src="js.js"></script>
<div data-role="page" id="page2">
<div data-role="header">
<h1>Page 2 Title</h1>
</div>
<div data-role="content">
go to page1
<p id="addstuff">Page 2 content goes here.</p>
</div>
<div data-role="footer">
<h4>Page 2 Footer</h4>
</div>
</div>
js.js
$(document).delegate('#page2', 'pageinit', function() {
$('<div />', {
html: 'Some text that was added via jQuery'
}).appendTo('#addstuff');
});
So I need to execute some JavaScript on page2.html. It actually works great (the div was created and you see the text). But when I'm clicking on a link to change the page, you can see, that jQuery is calling a hashtag in the URL first. So it looks like:
example.org/page1.html#/page2.html
when I clicked on the link on page1.html (just for a few milliseconds maybe) and then it redirects to
example.org/page2.html
I guess it's because of the id .. but I need this one for the pageInit (as far as I know).
Is this behavior normal ? Or am I doing something wrong. Maybe there's even a command to not call the hash tag.
Here you go:
It's important to note that if you are linking from a mobile page that was loaded via AJAX to a page that contains multiple internal pages, you need to add a rel="external" or data-ajax="false" to the link. This tells the framework to do a full page reload to clear out the AJAX hash in the URL. This is critical because AJAX pages use the hash (#) to track the AJAX history, while multiple internal pages use the hash to indicate internal pages so there will be conflicts in the hash between these two modes.
For example, a link to a page containing multiple internal pages would
look like this:
< a href="multipage.html" rel="external">Multi-page link< /a>
Src: http://view.jquerymobile.com/1.3.0/#Linkingwithinamulti-pagedocument

MVC3 Meta tag Dynamically change

I am working on MVC3, I am using Razor engine i have a layout.cshtml page which contains meta tag like
<meta property="og:url" content="http://www.mywebsite.com/" />
I have some content pages like abc.cshtml which has Layout.cshtml page as there's layout,so they are getting meta tags from layout.cshtml,i want that abc.cshtml should have its own meta tag like
<meta property="og:url" content="http://www.mywebsite.com/controller/abc" />
How can i do this? OR can i change meta tag dynamically??????
Yes you can pass that value from each or view action in ViewBag like below...
ViewBag.OgURL = "http://www.mywebsite.com/controller/abc";
then in you layout.cshtml
#ViewBag.OgURL
or set above head tag in you layout.cshtml..
#RenderSection("head", false)
and add in your view...
#section head {
<meta property="og:url" content="http://www.mywebsite.com/controller/abc" />
}

Simple desktop gadget won't save its data between runs

I'm trying to write a very simple Windows 7 gadget, which is easy enough. But I can't get any of the data I'm saving with System.Gadget.Settings.write/read (writeString/readString) to persist between runs of the gadget. I know it can be done, because all the other Microsoft gadgets do it. I'm obviously missing something crucial, but can't see it.
This is a very simple cut down example:
<html>
<head>
<meta http-equiv="MSThemeCompatible" CONTENT="yes" />
<meta http-equiv="Content-Type" content="text/html; charset=Unicode" />
<title>test</title>
<script type="text/javascript">
function save() {
var e = document.getElementById("name");
if (e && e.value) {
System.Gadget.Settings.write("name", e.value);
prompt("turnedout", System.Gadget.Settings.read("name"));
}
}
function load() {
var t = System.Gadget.Settings.read("name");
prompt("turnedout", t);
}
</script>
</head>
<body scroll="no" unselectable="on" onload='load()'>
<label for='name'>Name</label>
<input id='name'>
<input type="button" value='Save' onclick='save()' />
</body>
</html>
I've traced through the code and everything appears to go in the right places. What's missing?
Gadgets don't work like desktop applications with regard to settings. The settings are per instance of a gadget. Close the instance and you lose the settings. There are other limitations as well. There's a good explanation at: http://dotnetslackers.com/articles/net/SettingsManagerforWindowsVistaSidebarGadgets.aspx
Even I had the same issue, but when I moved the System.Gadget.Settings.write("name", e.value); to the html which is specified in the gadget.xml file, it wrote to the settings.ini file properly

Grails RemoteForm, Ajax doesn't work

I'm new on Grails and I have some troubles with Ajax (so I could have missed something). On my main gsp I want a select box, that, when I click on its options, makes appear another field on the same page to select other things. As the content in the second part is dynamic, I need somme Ajax. Anyway I haven't succeed yet. Here is my code :
main.gsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="layout" content="main" />
<title>Sample title</title>
<g:javascript library="jquery"/>
</head>
<body>
<h1>Selection de l'email</h1>
<div class="dialog">
<g:select name="selectTemplate"
from="${templateCategories}"
value="category"
noSelection="['':'--- choisissez un modèle ---']"
onchange="${remoteFunction(
controller:"email"
action:"printTestTemplate"
update:"listTemplates"
params:'\'category=\'+this.value'
)}"
/>
<div id="listTemplates">RRR</div>
</div>
</body>
</html>
EmailController
def printTestTemplate = {
println params.category //doesn't print anything
println "YEAAAAAAAAAH" //the same
render(view:"formSelectTemplate", model:[templates:EmailTemplate.findByCategory(params.templateCategory)])
}
formSelectTemplate.gsp
<h1>YOUHOUUU !</h1>
I've both tried to call a view or template (by renaming the gsp of course), but nothing worked. Nevertheless I don't understand, I followed the official doc. Notice that the HTML result creates no event on the select box, and that Firebug tells me there is no 404. So I must have missed something in the creation of the box.
select result in HTML :
<select id="selectTemplate" name="selectTemplate">
<option value="Refus">Refus</option>
<option value="Informations complémentaires">Informations complémentaires</option>
</select>
Did you forget comas between the arguments of your remoteFunction call ? like this:
onchange="${remoteFunction(controller:"email",
action:"printTestTemplate",
update:"listTemplates",
params:'\'category=\'+this.value' )}"

Resources