I'm using swagger for my ASP.NET WebAPI Services.
I want to show the documentation page on my base location.
When I want to show the Swagger UI I have to call this url: http://localhost:8080/swagger/ui/index or https://[your-url]/help/index
Is there any possibility that I load swagger on https://[your-url] and not at https://[your-url]/help/index
How can I get this working, without any redirect?
I only want to host my services and want to show swagger ui on the base route.
Is this possible?
I've just tried, however swagger would crash due to an empty URL template. I am not aware of a way to implement this without redirects or URL rewrites.
You can configure base route and swagger URL using UseSwaggerUi() method.
var baseRoute = "anything";
var swaggerUrl = "/swagger/v1/swagger.json";
app.UseSwagger();
app.UseSwaggerUi(baseRoute, swaggerUrl);
The swagger URL would be: https://[your-url]/anything
This code snippet is from a .Net Core 1.0 application, however hopefully you can configure your Web API accordingly.
A possible option could be IIS URL rewrite rule.
Related
I was learning about Spring REST HATEOAS. But, I am confused about how we use it on the client end..
I mean, let's say I want write a client app using Angular JS. So now I don't have to hardcode the URL's to make REST API calls? And instead i'd use the "rel" attribute that gets returned?
for example, from angular JS,
I'd use the root URL "/products"
It returns links to individual products (Which I believe will be populated on UI)
User selects a product and angular will fetch the product details, along with relevant links to that product to delete, edit, etc..
If user clicks on delete, Angualar will use the URI specified in "rel=delete" to delete that product..
Is my understanding correct?
Is there a sample angular code, that doesn't hardcode URI but use the rel attribute?
I'm working on a project converting older .aspx pages to newer MVC pages. I'm currently using the routing function to map the existing legacy pages to use the newer MVC pages behind the scenes. This is working great because it is preserving the existing URL, however, whenever the controller needs to redirect the user OR an MVC Url.Action link is used, the URL it sends the user to is the MVC url and not the routed legacy page url. I realize that this is how its suppose to be functioning out of the box but I was wondering if MVC has "reverse routing" functionality of some sort. By reverse routing I am looking for something that allows the Url.Action("action") to return the routed .aspx associated url with the specified action instead of the default /controller/action link.
So for instance,
here is a sample route
context.MapRoute("AboutUs", "pages/aboutus.aspx", new { controller = "default", action = "aboutus" });
This enables domain.com/pages/aboutus.aspx to run the new MVC action "aboutus" from the DefaultController behind the scenes perfectly.
However, if on another MVC page I have a link created by
Url.Action("aboutus")
it points them to domain.com/mvc/aboutus. I would like it to point them to domain.com/pages/aboutus.aspx to keep uniformity across the site.
Thanks for any insights that you can provide. I might end up having to override the Url.Action method to look up the route and return the mapped url but I just wanted to check for existing functionality so I don't reinvent the wheel.
Try using the RouteUrl extension method, which matches the route by route name rather than route parameters, like so:
Url.RouteUrl("aboutus") // route name
MSDN: http://msdn.microsoft.com/en-us/library/dd460347
Background
I'm investigating the use of Orbeon Forms to integrate into our
ASP.NET MVC3 web app by building a simple MVC3 app to figure stuff
out.
I have a Win2008 R2 std server running Tomcat 7 and Orbeon 3.9.1 PE
trial on our HyperV server. This is working and I can create forms and
then use the forms to submit data.
I've created an empty MVC3 app on my local dev machine. It has an
Index action on the Home controller that returns a page that has a
bunch of links to the add new URLs of some of my forms on the Orbeon
installation. The links access an Add action on the Home controller
which uses a WebRequest object with the ?orebeon-embeddable=true
querystring parameter tagged on the end to get the definition of the
Orbeon submit form page. I replace the relative URLs in what I get
back to make them absolute. I then insert that into a basic view and
display it.
Problems
HOWEVER! As soon as I do interact with the Orbeon form in anyway, e.g. click inside a single line textbox field (IE9) I get a JS error
in the script file "orbeon-[random guid style value].js" line 121 with
the line "AjaxServer.exceptionWhenTalkingToServer(e,formID)"
highlighted with the error being "formID is undefined".
I'm not sure where to start looking here as I am unfamiliar with
Tomcat and only know what I can decipher from the Orbeon docs.
Anybody tried to embed the form runner like this and experience this
error?
What I tried next
[Update]: The MVC Json() method got me thinking that perhaps the
Orbeon test site I set up on the VM did not like the fact it was
getting AJAX requests from the MVC app on my dev machine. With this in
mind I tried installing the CORS filter into the Orbeon app from
dzhuvinov.com. According to the docs after adding the relevant
config to the web.xml file the default behaviour is to pretty
unrestrictive, i.e. it should let everything through. Unfortunately
after restrating Tomcat this didn't help.
[Update 2]: Okay seems like the CORS docs are a bit out of date and
the defaults are seemingly the opposite so setting the initial values
for that seems to sort that out somewhat - although IE9 still gets the
JS error message. Meanwhile in FireFox 12 things are going better but
now the issue is how to pass the JSESSIONID cookie Orbeon sends me
back when I embed the runner in the MVC view such that when you
trigger any of the AJAX on the Orbeon form it sends the JSESSIONID
cookie as well.
Well I guess my title and info were slightly misleading so I may as well close my own question with the follow "answer".
In order to embed in an MVC3 app (read as any non-Java backend I would imagine) Orbeon Forms Runner and have it work I had to do the following:
Configure the CORS filter for my install of Orbeon Forms on Tomcat 7 (Dzhuvinov.com) to allow cross-domain AJAX.
In HTML partial's returned from Orbeon make relative URLs beginning /orbeon/xforms-server/ absolute calls to a custom proxy. Store the JSESSIONID in the ASP.NET MVC Session object.
Write controller actions for the proxy to handle requests. This simple proxy forward requests on to the Orbeon Forms install after setting the JSESSIONID cookie with the value stored in (2).
I have added an MVC3 web application to an existing website that consists of plain old html files. This works great when you request a specific file but what didn't occur to me was that by changing the site to use .Net 4 it no longer took any notice of the default documents setting in IIS (IIS 6 in this case). So for example I can request www.something.com/index.html but if I request www.something.com I get a resource not found error page. Is there a MapRoute in Global.asax I can specify to map the site route url to index.html?
Looks like something has changed, I had to do
routes.IgnoreRoute("");
ASP.NET complained about the route starting with "/"
routes.IgnoreRoute("");
Allows the request to fall through to the default documents defined in the site configuration. I only have a single controller and route in this project that I use for ajax requests from the client. I want the rest of the site to continue to behave as it did when it was just plain html. With routes.IgnoreRoute("") the MVC3 app ignores the request which allows IIS to return the default document. Thanks all for your suggestions.
in global.asax you can try to define a rules like this one
routes.MapRoute("", "index.html", new { controller = "Home", action = "Index" });
But I'm afraid that with IIS 6 you have to handle the Wild card mapping.
That's normal. IIS 6.0 does not support extensionless urls. You will need a wildcard mapping as explained by Phil Haack.
I have MVC3 application with SSL. I want particular page URL should always add Https. Can someone tell me how to do this. Below is the Route in Global file.
routes.MapRoute("root22",
"paybill",
new { controller = "Home", action = "PayBill" });
One more thing if my URL has https in front than should all the paths in the page also use https or not necessary?
You don't need to mess with the routing to accomplish this. Just use the [RequireHttps] attribute on your controller/actions.
[RequireHttps]
public ViewResult YourAction()
If it can, it will redirect to https. Your outgoing links don't have to use https, but when loading javascript, css, images, etc. then it should otherwise the user may get a mixed content security warning.
Above attribute works fine if you want your whole website in https after redirecting using that particular action.
But you want to secure only a single page rather than whole website, just use below code.
http://www.codehosting.net/blog/BlogEngine/post/More-fiddling-with-MVC3-and-https.aspx