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.
Related
My situation is: I have a Spring MVC project is running now, I need to include a file in normal form object to submit to server side to handling.
I did quite lots research recently, I found there is no way to submit a file in a regular form as file upload submit form has to configured to support file encode (enctype="multipart/form-data"). it is impossible in regular form.
Ajax provides a way to do the file uploading in javascript by javascript function call, but they need a individual servlet to listen to the javascript call. My project already did everything in modelandview controller to handle form object and model object logic.
My question is: May I add a file upload method in my modelandview controller to listen to my Ajax function call? If it is true, what's looks like?
Please help!!
After a while works on this issue, I found some thing is very interesting. If I want to use some thing else in my Spring MVC controller. I have change my controller class to "extends MultiActionController", which means make the controller to support multiAction, and then you can add other class and action in Spring MVC modelandview style controller, even you can use "webservlet" or "ResponseBody" style controller functions in your MVC controller, you don't need create other new controller to support Ajax controller, you only need update your existing controller by adding some functions. it is much easy to manage you existing code too.
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 am using ASP.NET 3.0 MVC with membership provider. I have to make modification to the default implementation we get with membership related code. I have to move LogOff Hyperlink in the master page. Initially this link is in-visible but once authentication is succesfful I need to make it visible. This action will happen from Controller for authentication and I am not sure how to access the hyperlink defined in a master page from a different controller. Any ideas how this could be achieved keeping the spirits of MVC design?
You could create another action in your AccountController to determine if the log off link needs to be displayed. This action has a partial for the html. Call this new action from the master page and check in that action if the log off link needs to be displayed.
#{ Html.RenderAction("displayLogOff", "Account"); }
I'm not sure why you need to make a modification, as this seems to be the default behaviour, but typically you would use a partial view to display the log off hyperlink. This partial view can run an action, and in this action you would send a model to the view which could include a flag for if the user is currently authenticated. Alternatively, you can just check Request.IsAuthenticated in the partial view directly.
I'm not sure I understand. The default implementation already does this. It works regardless of what controller you're using. The reason is that the master page uses a partial page that specifies the method and controller.
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
I've got a template for a partial that I'd like to use and I'm wondering if it's possible to just render the thing without needing to send a mock request to a controller. I'm never going to need to render this to an AJAX call, so it seems silly to set up a controller and action, not to mention the security issues with making a private partial open to the world.
I think you need render_view. It skips both layout and controller action.