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
Related
I am using the Salesforce Sites URL rewriting feature, and need to retrieve the 'friendly' URL from the browser bar for some other processing. Is there any way I can retrieve this from within either one of the sites pages (so I can pass into a component as an attribute) or from a component controller directly?
To explain further, I am seeing a url in browser presently of 'site.force.com/examplesite/amazingpage' but if I try to retrieve $CurrentPage.url to pass into a component, or use Url.getCurrentRequestUrl() from within a component controller the result is a typical salesforce url ie. 'site.force.com/vfpage?id=123456789'.
Any suggestions most appreciated.
Cheers,
CH
Sorted.
Was obvious in the end - just added an additional method to the url rewriter class that allowed me to pass in a single url for rewriting, rather than trying to retrieve the re-written url from the view.
Cheers,
CH
I am developing single page application using hashbangs(#!)
So the application urls are in format #!/api/generalelections.
When i directly enter this url in browser the mvc does not seem to recognize hashbangs ,it always take me to default action mentiond in glolab.asax.
Could anyone provide me solution to handle this problem to redirect to proper action which is api/generalelections
Everything that goes after # is treated by browser as anchor tag and will not be supplied to the server.
In your Xhr requests to the server you should use 'normal' uris, but not your navigation ones.
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
I have an http handler which picks up all requests for my custom extension .page . This works fine with old fashion asp.net where I simply do a Server.Transfer to the aspx file of choice.
However, I would like to move this to MVC and instead reroute to either a Controller or a View. Doesn't matter which though I would prefer to a Controller.
Any help on this subject is appreciated.
Thanks!
I'd go about adding a new entry in the RouteTable.Routes ignored routes:
routes.Ignore("{*allcustomextension}",
new {
allcustomextension = #".*\.ext(/.*)?"
});
This will allow the handler to be invoked as a physical resource.
To redirect from the handler context to a View use:
System.Web.Mvc.UrlHelper.Action("ViewName", "ControllerName");
Firstly, you should redirect only to a controller which will select the view to render but think that you don't need that custom handler. Try something like that (you should change it somehow to match the url format you have)
routes.MapRoute("page", "{controller}/{action}.page");
If that doesn't work and you really want to redirect from your handler, combine the ignoring route from Xander with
Response.Redirect(System.Web.Mvc.UrlHelper.Action("ActionName", "ControllerName"));
Afaik, Server.Transfer works only with asp.net classic so your only option is a redirect.
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.