In Java on WebSphere Application Server if I want my servlets, etc., to start with a certain root path, I use the context-root property in the EAR deployment descriptor (application.xml). For example, my servlet is named GetData, but I want the URL to be www.mysite.com/secure/restricted/GetData, so I set the context-root to secure/restricted.
How do I do that in ASP.NET on IIS? Is the some kind of configuration setting for the application?
One option would be Url Rewritting - http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
On the other hand, if you have your dynamic asp.net site separated from the rest of your content, you can add the folder secure/ and configure in there through the IIS Manager to point restricted to your asp.net site (regardless of where you have it stored).
That said, I don't know whether the WAS context-root give you something extra, for links to other info outside the asp.net site.
In .Net Core 2.0, there is an applicationUrl property in launchSettings.json:
By default, it will be "http://localhost:port/GetData" or "http://localhost:port"
Just change it to your final URL:
"http://localhost:port/secure/restricted/GetData"
Related
Is there a way to set a context path in a Spring Boot application running in GCP AppEngine Standard?
I want to add an implicit prefix to all my resources. So if the #RestControllers are, say, /a and /b, I want that to access them, their URL is always /my/prefix/a and /my/prefix/b. In normal, embedded mode in Spring Boot, this works by setting server.servlet.context-path. However, this setting is not respected by AppEngine. In it, /my/prefix/a returns a 404 and I have to use /a instead
How do I add a common prefix to all my resources in AppEngine Standard? This seems basic for AppEngine's services/modules support to avoid duplicating the prefix in all controllers, but I can't find how to do it
so per my conversation with the Google Cloud Support team - I got confirmation that the App Engine Standard does not support / honor the port & context paths set in spring-boot.
This is the response I got from them:
"With regards to your concern about App Engine not honoring the manually set port number and context path, this is because it should be setup in yaml file.
For the port to be set as 7777, it should be done by port forwarding. However, port forwarding is only available in App Engine Flex. For more details about this, you may visit this page [1].
For the context-path, you may use the tag and include in appengine-web.xml file. This sets the path in your application that contains the static files. You may check this document [2] for more information.
You could also include the tag in your appengine-web.xml as it is also useful for serving static content such as images, CSS stylesheets or JavaScript files. You may use this reference [3].
With this solution or workaround, this also address that spring-boot application could be deployed in App Engine.
If you have further concerns, just let me know.
Thank you and have a nice day!
[1] https://cloud.google.com/appengine/docs/flexible/custom-runtimes/configuring-your-app-with-app-yaml#port_forwarding
[2] https://cloud.google.com/appengine/docs/standard/java/config/appref#public_root
[3] https://cloud.google.com/appengine/docs/standard/java/config/appref#static_files
"
However, setting the to some value did not still pick it up as the context path. So had to abandon GAE unfortunately. Wasted so much time on this - hope this is useful for others that are struggling with this.
Let's say I have:
foo.war
bar.war
Is it possible that I deploy them both somehow to the same deployment path? E.g., to access it at:
http://localhost/baz
Are the content of the war files merged somehow? How are file conflicts handled (e.g., let's say both of them has an index.jsp file)?
Thx in advnace!
The servlet specification explicitly forbids this. Deployed web applications may not have identical or overlapping context roots. From the Servlet 3.0 specification, section 10.5:
Since the context path of an application determines the URL namespace of the contents of the Web application, Web containers must reject Web applications defining a context path that could cause potential conflicts in this URL namespace. This may occur, for example, by attempting to deploy a second Web application with the same context path.
Yes & no.
I don't think it's possible to somehow merge them into the same file system path within a servlet container like Tomcat (unless you were to write some kind of complicated, intelligent script to do so). For starters, each .war will have a WEB-INF/web.xml file, and each will rely on the contents of its own file to function -- which would win?
But you conceivably could...
Deploy to 2 different contexts (or containers, or hosts), and employ some kind of load balancer (hardware or software) to route some requests to one, other requests to the other.
Use an "overlay" strategy (such as Maven Overlays) to make a second (and final) .war that is a derivative and extension of another .war file
I want to apply filter in below URL's.
http://10.78.97.29/robots.txt
http://10.78.97.29/sitemap.xml
https://10.78.97.29/
Since they does not contain any specific URL pattern , I am not getting any idea. And in which web.xml I have to add that filter mapping. I am using Tomcat as a webcontainer.
Thanks in advance.
Tomcat by default uses the web application named ROOT to serve the application at the root folder of the server. You can either handle the requests there or just have the files contained in the web application.
You might want to read about tomcat naming for more details, explaining this behaviour.
Alternatively, you can also have an Apache httpd in front of your tomcat and handle those files there.
I have an application with name test.war.
Because of Apache installed on my server I have to use another port number for Tomcat applications so after deployment this application available at domain.com:8080/test/.
I decided to create a subdomain in order to remove that ugly 8080 from url, so I setted up the server like described here. So now test.domain.com reffers to domain.com:8080/test/.
Everything seems fine except of one problem - because my application is not ROOT.war and I am using spring:url function every url in the application is translated to /test/bla-bla. So I removed that function. But still have a problem with spring security because it still translates an urls relative to app name i.e. /test/bla-bla.
How can I solve that problem?
Thank you
UPD: I don't want to deploy it as a ROOT application because I have two or three such applications and I wanted to create a subdomain for each one of them
Spring Security doesn't "translate" URLs. In fact this isn't specific to Spring Security. You'll run into similar issues with any application which does redirects. If you want to hide the context paths of applications which are behind a proxy, then you need to rewrite the URLs at the proxy.
I'd recommend you read the Tomcat Generic Proxy Howto and the section on URL rewriting in particular, as it specifically addresses this issue.
My old way using mod_jk in apache and configure virtual host in tomcat
In the JSP file, I refer to CSS as below
/<%=request.getContextPath()%>/css/styles.css
while the home link is set to
/<%=request.getContextPath()%>/
so this worked fine when I use mod_jk in apache to work with tomcat using ajp;
When I try to configure reverse proxy as below
ProxyPass / http://localhost:800/mywebapp
ProxyPassReverse / http://localhost:800/mywebapp
the home page can be retrieved fine but the css request becomes
http://mydomain.com/mywebapp/mywebapp/css/style.css
so the css file can not be retrieved correctly;
I think one possible way is to always use relative path like ./style.css or ../style.css
a. since header/footer are shared, and the home page is in a different level with detail page, it's inconvenient to use relative path because they're at a different level
b. still, I think the home link will have to be /<%=request.getContextPath()%>/
so I wonder what's the way to set contextroot fine in java web and also work fine with reverse proxy?
thx a lot
As I know your application server (Tomcat) isn't able to be aware of a reverse proxy presence. Generally speaking, it can be contacted through any number of reverse proxies or directly by browsers. A network configuration is usually used to limit this, not HTTP or Java.
So, you must accurately rely on relative URLs to make your application work well.
When I have to deal with reverse proxy presence (almost always due to SSO architectures), I embed a "junction" configuration string item (the portion of the URL used in the proxy to map the application) and use it in the only places where I need to build an absolute URL.