how to access IIS server variables in Rails - ruby-on-rails

How do you access IIS "server variables" in Rails? Are they passed in the ENV object?
We are using IIS to reverse proxy some Tomcat instances running a Rails app using JRuby. It looked like IIS can send server variables per request. I would like to dynamically change view content based on the values of some of these server variables.

Retrieve server variables set by IIS by inspecting request object:
request.env['some-variable']

Related

Rails forms leading to Mixed Content warning

In my Rails app I use both Rails' native form_tag method and the simple_form_for method provided by the simple_form rubygem.
Both of them are leading to the following warning in the chrome console:
Mixed Content: The page at 'https://example.com' was loaded over a secure connection, but contains a form which targets an insecure endpoint 'http://example.com'. This endpoint should be made available over a secure connection.
And indeed, the rendered HTML forms use the http protocol for their action attribute.
What is the reason for that? All my other URL's use the https protocol.
You have not correct protocol set up for your environment.
Your server is running on HTTPS and form creates HTTP URL.
You need to tell your URL helpers to build the URLs with the same protocol as your server is running for your environment.
Development should run on HTTP, staging should be HTTPS and production as well HTTPS.
There are different ways how to do it. The best is to set protocol in your environment config file. So place this line:
Rails.application.routes.default_url_options[:protocol] = 'https'
into your environment config file like production.rb and staging.rb.
Another approach is to set the default protocol per controller action. Check this one for more info.
In case you are using the mailer, also check your mailer protocol settings. As described here.

Deploying the ASP.NET Web API

I am creating my first ASP.NET Web API. Created the application, build them and ran the application by calling the URL like http://localhost:35432/api/Sample?id=1&id=83 and returns the JSON file as response.
But I dont see anything with respect to this application on the IIS manager. Where do I find them or do I have to set up something. I am not sure how we will be deploying the application from DEV to TEST server.

Connecting between IIS Express and Jetty on Azure Cloud Service Virtual Machine

I have an Azure Cloud Service Virtual Machine with 2 server:
Java project using Jetty server at http://localhost:8999
ASP.NET MVC project using IIS Express at http://localhost
I am using Http request to make connection between 2 server.
In my VM, inside ASP.NET MVC project, I use http://localhost:8999 to get data from Jetty server. It works perfectly with short response time (from 100ms to 6000ms).
However, when I access the IIS Express via Internet using http://mydomain.cloudapp.net. It does not work anymore.
Then I change my config file in ASP.NET MVC project to use http://mydomain.cloudapp.net:8999. It works but with long response time (from 15s to 40s). This is because of my slow internet connection.
My question is:
If I access IIS Express via Internet, to avoid external internet connection, is there any solution which let IIS Express know that it's target is local?
Which means I can still use http://localhost:8999 in my config file in ASP.NET MVC project, and it still work if I access IIS Express via Internet not only via localhost.
The main question is how you connect between the two servers? From the client side (JavaScript) or the ServerSide (Controller action/private method).
From what you describe it seems that you make XMLHttpRequest (JavaScript, AJAX, jQuery, etc.) call from your client side directly to your Jetty Server. In order to avoid roundtrips, you have to change this and make XMLHttpRequest to Your Server (MVC), then on the MVC backend (Controller action, or private method, or Repository) make the Jetty server call and transparently return the answer to the calling client.
You can also try tweaking your Jetty Server settings to allow for longer script execution.

Accessing ASP.NET MVC Variables in Elastic Beanstalk Web.config

I'm trying to update my elastic beanstalk configuration with custom web.config keys for our production servers, passwords, etc.
According to these .NET docs, I can use ConfigurationManager.AppSettings to access these variables. I have some defaults that are in there for my local machine, and these are what get read, instead of the overrides in the web UI.
Specify up to five additional key-value pairs by entering them in the
PARAM boxes.
You might have a code snippet that looks similar to the following to
access the keys and parameters:
NameValueCollection appConfig = ConfigurationManager.AppSettings;
string param1 = appConfig["PARAM1"];
How do I access my web.config overrides in Elastic Beanstalk?
It turns out that the configuration variables will only be added if they do not previously exist in web.config. This is a different behavior than I have experienced in Azure, where parameters would override web.config.
You can validate this by RDP'ing into an EC2 instance, and viewing web.config. New parameters will be added, but ones that exist in web.config will be ignored.
You can replicate the override behavior by using the xdt "Remove" Transform in Web.Release.Config
<add key="foo" xdt:Transform="Remove" xdt:Locator="Match(key)"/>
Then set the "foo" parameter in Elastic Beanstalk using the web tool, file config, or CLI

Grails redirect with reverse proxy

We've developed a Grails application that uses redirects.
Beacuse of external reasons, we are just recently using reverse-proxy, to split some traffic to domains:
From:
demo1.company.local (the server itself)
To:
tomcat.company.local (for all java applications, including our grails app)
lotus.company.local (for all Domino applications)
Since tomcat is only configured in the hosts file on the demo1 server, the redirects do not work when I access the application from anywhere else then the demo1 server itself.
I've tried to solve this using "absolute" and/or "base" parameter in Grails' redirect(), but if I understand correctly, this is Grails 2+ only and we're using Grails 1.3.4.
Are there other ways to redirect to a specified host?
Am I misusing things?
Thanks,
Bram
If you define grails.serverURL in Config.groovy, redirects with absolute:true will use that value for the URL.

Resources