In my MVC Web application, I have created two controllers. One for handling requests coming from Mobile devices and other for handling desktop browsers.
I am trying to call the appropriate controller's action depending on who is calling the application. This check will be done by a custom logic which is ready with me.
What will be the best approach to achive this dynamic redirection to controller? My approach is to use one HTTPHandler (ashx), in which I will check the source and then give a call to appropriate controller. The device/browser will hit the URL pointing to this ashx file.
I tried somehting like this..... in ProcessRequest() method of my handler.
<source checking logic>
...
...
var webRequest = HttpWebRequest.Create(MyFinalURL);
var response = webRequest.GetResponse();
context.Response.Write(response);
Will this be the best approach? or is there any better alternative? Will HTTPModule also work for this prupose? Please suggest.
Also how will I redirect to controller action from ashx file?
Take a look at Scott Hanselman's blog post on mobile capable view engine
Related
In http module's BeginRequest event, how to find that current request is of MVC and not of traditoinal ASP.net ?
What are you trying to accomplish? If you want some code to run prior to a particular controller action, or all actions of all controllers you can use action filters. These can be wired up using attributes on your controllers. Alternatively you can set them up dynamically using DI and interception, etc.
I think you're trying to do something in a way that is limiting your options... filters are most likely what you want.
In an ASP.NET MVC 4 application, I would like to get the URL of the site calling the application. That is, I would like to be able to change the web site slightly depending upon which URL it is called from, and as such need to know how to tell what the calling URL is? I would then call a different index.cshtml file depending on which site it is called from.
Any help would be appreciated
I'm not completely sure what you want to do, but would this do the trick for you:
Request.UrlReferrer
Or
Request.ServerVariables["HTTP_Referer"]
Although I'd prefer the first one.
I have an mvc4 application that I am looking at hosting on azure websites. The only task is to take a code from a parameter and redirect to a page within our main application. We have a .co domain so we are issuing shortcodes like mydomain.co/abc I check the code in this example abc and redirect it to somewhere in our main application.
My question is do I just create a controller and do the redirect from the controller or can I do this before the controller? I want it to be as lightweight as possible.
Thank you
A controller action taking the parameter, querying some data store by passing it this parameter in order to retrieve additional data and finally redirecting to the corresponding application seems fine. Another possibility is to write a custom route that will perform those tasks but IMHO having a controller action to do it seems easier.
Hi
When migrating from ASP.NET to MVC ASP.NET it looks like the MVC is more AJAX friendly.
but still I run into design issue,
Does someone knows Microsoft intention about the design when calling AJAX methods?
Where do I need to put this methods by default, in a separate controller, the same controller?
Is there any kind of official info about it?
Thanks
I don't think that there is any official best practices. Personally I like to follow RESTful conventions when organizing cotrollers and actions no matter how those actions are consumed (AJAX or not).
You might wanna try on having a review on some asp.net samples here. This will give you some ideas. :)
I would suggest taking SessionState into consideration when making the choice of method placement.
For instance, I would move ajax actions into a separate controller if I am using session state in regular actions, but not in ajax actions (which makes sense for me) and I would like the ajax methods to execute asynchronously. Then I put those ajax methods in a separate controller and mark the controller as [SessionState(SessionStateBehavior.Disabled)] (or ReadOnly). I have found this to be a great improvement in terms of performance.
Note, that you use Session when you use TempData, ViewData or ViewBag variables.
SessionState is explained here:
ASP.NET MVC and Ajax, concurrent requests?
I need to create a helper function for UpdatePanelAnimation extender from AjaxControlToolkit in asp.net mvc. I downloaded the toolkit and loaded the js files into my project.
Can someone please tell me how should I write this helper function and what all parameters are to be passed into it.
I am new to asp.net and mvc
thanks for the reply. but we have to include more helper functions in mvc in the near future. so i need to implement this anyway.
Since you have jQuery, using UpdatePanel and UpdatePanelAnimation is not desired in ASP.NET MVC. You can use jQuery Animate method:
http://jqueryui.com/demos/animate/#source
First you call animate to hide panel, then you use post or get ajax method and in callback you call animate to come back to previous state. If you do it properly, it will look like UpdatePanelAnimation and have very nice looking code.