Is there a way to retrieve the hostname for the server Thymeleaf is running on?
I would like to display the first part of host name hidden on the page. To triage when behind a load balancer.
You could just get the hostname on the server-side and add it as a variable to the model in your controller, just like any other variable.
Something simple like:
Controller code
model.addAttribute("myHostName", SomeUtil.getHostName());
HTML
<th:block th:text="${myHostName}">[host]</th:block>
Related
Can any body help me to resolve url (route url) in MVC
when i enter into the system it redirects me to Dashboard it works perfectly.
I have user defined menu whose routing value stored in database as follows
suppose i entered into the system it will redirect me to Dashboard page
suppose i want to redirect to usermaster page then url should be as follows
http://localhost:6782/Home/Index
but when i try to redirect to home index page the url should look like this
http://localhost:6782/Dashboard/~/Voucher/Create
i want to remove Dashboard/~
how plz let me know
If you're using IIS URL Rewriting within your MVC application, e.g. internally treating http://yoursubdomain.example.com/MyController/MyAction as http://hosted.example.com/yoursubdomain/MyController/MyAction, Url.Content() will generate a correct subdomain-relative link. ResolveUrl() will generate an incorrect link in this situation.
Source:Should I use Url.Content() or ResolveUrl() in my MVC views?
You should consider about #Url.Content("~\Action\").
You should not store the URL in the database as the URL may change according to the routing rules.
Try to store the controller name and action name in the database and in your code that builds the menu use #Url.Action and pass the controller and action retrieved from the database
I have two sites which communicate with each other. I'll call them mainsite.com and backend.com for this example.
mainsite.com is the site that people go to, and this loads an iframe which loads in backend.com, which is a Rails site that handles all of the login & signup stuff. At the end of the login process, backend.com generates a url which has an encrypted set of params which are used to log the user into mainsite.com.
The way that this is currently working is that backend.com controller generates a url like this "http://mainsite.com?auth=2347qweiuyqi" and saves it in a variable called #redirect_url, then (in the iframe) renders out some html which contains some javascript to redirect the parent page:
<script type="text/javascript">
$(function(){
window.top.location.href = "<%= #redirect_url %>";
});
</script>
This is working fine. However, we have a new situation where people can now access mainsite.com via a load of different urls (all subdomains on other sites, like mainsite.foo.com and mainsite.bar.com)
Now, when i redirect them to the auth url on mainsite, i want them to stay on whichever domain they're on. So, if they're on mainsite.foo.com, and loading backend.com in the iframe, then at the end of the login process i want to redirect the parent window to mainsite.foo.com?auth=2347qweiuyqi. Similarly, if they're on mainsite.bar.com they should be redirected to mainsite.bar.com?auth=2347qweiuyqi
My initial attempt at this was to change the javascript to get the domain name from the parent window, and build the redirect url by adding the params onto the end, then redirecting to this url. However, the iframe can't access the parent domain name because of cross-domain protection (ie the domains, "mainsite.foo.com", and "backend.com", don't match.
My next attempt was to have a javascript function on mainsite.com which takes the auth param and redirects to a url consisting of the current domain with that param added onto the end. But, i can't call a parent window function because of the same cross-domain restrictions.
How can I get past this? I have complete control over the content of both sites.
One solution which i know would work, but is a bit of hassle to set up, is to pass through the mainsite domain name through as a parameter in the src attribute of the iframe to backend.com, and then make sure that backend.com hangs on to that through the whole login/signup process, so that at the end of the process it can use it to build the whole url to redirect to. But, it feels like there should be a simpler way.
thanks, Max
EDIT - i've solved this by, when the first request comes through from mainsite.com to backend.com, saving the hostname of request.referer into the session, and then, later on when i come to do the redirect, looking it up from the session and adding the auth params on. This works but it feels a bit unsatisfactory so i'm interested in nicer solutions.
I am using struts-2.3.16.3 for my application. My action implements the “ModelDriven” interface. Using interceptor reference as defaultStack.
The problem that i am facing is, all the special characters (non keyboard characters like ®, ℗) are disappearing from my model property by the time they reach to my action class. Other special characters like # # $ etc able to see those in my action.
Do i need to configure any other interceptors in the stack?. Help needed if i am missing in configuration.
Example: If i enter Piracy℗symbol in my text field, in action class when i print property value it shows Piracysymbol.
Thanks,
Ramesh
I think the problem is that you have not mentioned the content-type. Try putting
<%# page contentType=”text/html;charset=UTF-8″ %> tag in your code if you haven't already. If the problem still persists write your code like this
<s:text name="username"/> <s:property value="getText('username')"/>
Hope this helps.
This is a bit of a puzzle for me.
I need to capture the URI Query string passed to the Home page.
As a user travels to different pages on the web site, I have a partial view that needs that URI query string.
I need a dynamicly created link in the partial view, that equals the original call to the home page.
Example -
If the user goes to - http://www.mysite.com?mode=Joe , I need the dynamicly created link to equal - Http://www.mysite.com?mode=Joe
If the user goes to - http://www.mysite.com?mode=Tommy , I need the dynamicly created link to equal - Http://www.mysite.com?mode=Tommy
FYI - The partial view is used in the _Layout.cshtml file. the call inside - _Layout.cshtml looks like this -
#Html.Partial("MyPartial")
Thanks!
There are a number of ways to do this, but probably the simplest would be to save it to the session on your home page, and then access that session variable from your partial.
You will need to decide what to do if the session expires.
Another possible way would be to write it to a cookie on the home page request and then access the request cookie in your partial. Again, you'd need to decide on an approach for cookies disabled, or wiped out during browsing.
Alternatively, you could look at something like the approach being used in the link below to set a language across the site. Exact implementation would differ, but concept is the same:
Howto automatically add a specific value from current route to all generated links?
My application works fine when I have only one parameter.
e.g.
/Product/Index/2
/Report/Sales/08-2009
But it failes when I add one more part to the url. Let's say I want to add the end month-year parameter to the url routing. Mow it becomes:
/Report/Sales/05-2009/09-2009
I do get both parameters in my action method. I parse it and retrieve the data and pass the Model to the View. With this scenario it throws the client side JS error when I try to access any of the form elements. I get "object expected" error. The same view works fine using just first parameter. What could be the issues here?
I also loose the CSS styles when this error occurs.
Thanks
well, without seeing any code at all this is difficult to troubleshoot, but I'd say it's likely because you are referencing your javascript and css files using a relative path like:
../content/scripts/myjavascript.js
Adding the second url parameter has caused the browser to be unable to find the urls because you have added what looks like an extra level of depth to the url.
You should provide absolute urls to your scripts and css files. An easy way to do this is to use the "ResolveUrl" method like so:
<%= ResolveUrl("~/Content/Scripts/myjavascript.css") %>