In my application I have various Views and Controllers.
So naturally when one navigate through pages the URL will change based on the Controller and the View;
E.g.
http://example.com/home/index
http://example.com/account/register
http://example.com/product/newproduct
But I would like to keep the Controller and View name in the address bar secret, in other words when one would navigate, the address bar always shows http://example.com
Does anyone know how to hide these routes? I'm an using ASP.NET MVC 4 C# application.
Basically just need the server to keep track of the pages.
Unfortunately, I believe that this is not going to be an easy task to accomplish. The MVC routing engine needs certain information to deliver the request to the screen and that information is handled when you map the route. Furthermore, you can imagine the kind of trouble people could get into if the browser allowed sites to alter the address ad hoc. Take a look at this video. It's pretty good about detailing how the routing engine works Pluralsight
Related
I have made a new project using the ASP.NET Web Application template in Visual Studio 2015. Then I selected MVC and Individual User Accounts to specify the template further. The solution I got is complete in that it offers me all the web pages you need for account management such as registering and logging in.
However, now I want to hook in a Xamarin.Forms mobile client to this account management scheme. I am making a native UI to register users, instead of redirecting them to a webpage or webview. I want to send user registration data, such as username and password, from this UI to the server so it will create an account. This means that I don't want to use the webpages offered by my MVC app, but rather send the registration data to the server and have it create an account, notfifying me of succes or failure.
I am anticipating that I would need to either use HTTP POSTs to login and registration endpoints in the AccountController or implement a public API. However, doing a post will return a webpage, and my client is not interested in a webpage.
I think one of the above should be possible to implement quite easily, but I am having a hard time searching for answers or methods, since I don't know how to phrase my problem properly, and with the abundance of guides on MVC, all my results are muddied.
Is my idea of this being possible flawed or have I missed a fundamental concept of MVC? What are the steps I should take in order to make this possible?
One misconception is that doing a POST will return a webpage. You can return any type of content from an MVC controller. But your account registration endpoints should be Web API controllers that return JSON. That JSON can be as simple as containing a boolean that indicates if the action was successful or not.
You do not need to use MVC at all. You can completely do away with the account controllers and views that the template created for you. Just copy the code that you need from the MVC controllers into your Web API methods.
You're right, this is quite easy to do.
I think, You can use ASP.NET Web API for doing this task. On server, you host your API for registering the users as well as logging into some client application.
Now, You need to consume this API in a client application. The client application could be a Console application, Windows application or a Web application. There are lots of tutorials about making an Web API on official ASP.NET site.
I am working on a large production SAAS Webforms application that is going to be slowly migrated to MVC 5. We want to be able to let some customers 'opt-in' to the new MVC pages as they are deployed based on a configurable setting.
The MVC application will be in the same project as the webforms application. The conversion to MVC will go feature by feature to basically create a complete MVC application standing side by side with the webforms application. Once all features are implemented and customers have converted we will remove the webforms project and keep only the MVC project.
If a customer 'opts-in' then we want them to view any MVC views that exist instead of the original aspx page. If an aspx page hasn't yet been converted to MVC OR they customer has not opted-in, then we want them to view the aspx page.
My main concern is preventing the user from manually entering in a url and going to an aspx page when they should be viewing a MVC page or vice versa. Since this application is a multi-tenant system, it cannot be just set in the route configuration because those are only loaded once when the whole application starts. Whatever solution needs to dynamically check the opt-in setting for each user.
Where would be the best place to honor the 'opt-in' setting to force the user to the new MVC route instead of the legacy aspx page if both exist and what is the best way to implement this logic?
A couple of co-workers mentioned that it might could be done using a HTTPModule that checks a collection of aspx page to MVC route mappings.
Basically:
If optInToMvcSetting == true && url.contains(".aspx") Then redirect to corresponding route found in aspxToRouteMap.
If optInToMvcSettings == false && !url.contains(".aspx") Then redirect to corresponding aspx page found in aspxToRouteMap.
Does anyone have any thoughts or advice?
Why not use both?
Leave the WebForms aspx pages as is and then add the MVC routes as features are converted.
Then you can simply maintain two separate navigation renderings, one for WebForms and one for MVC. By default show WebForms but if a user opts in, show MVC. A browser cookie would be sufficient to provide this functionality.
The MVC navigation will initially include aspx links but as the conversion progresses these will be swapped out for their MVC counterparts.
The MVC routing is smart enough to distinguish between an MVC route or an aspx page.
This question contains information for your problem.
I have to build a Web-Application using ASP .NET MVC. It has to serve different customers, each customer accesses the Page via another domain. With this domain the Application is supposed to load the customer specific data. It also has to provide a login mechanism.
I'm fimiliar with JSF, there I would solve this problem via webfilters.
Does ASP.NET MVC provide something similar to webfilters or is there an even better solution so solve this problem?
I really wish there was a tutorial or an example that adresses this problem, but after hours of googeling I could not find anything. I'm probably searching with the wrong keywords, but I don't know how mechanisms like this are called.
There are several ways of doing this, for example you could use routing (Is it possible to make an ASP.NET MVC route based on a subdomain?) but I would simply go with getting the username from the URL.
var user = Request.Url.Host.Split('.')[0];
My client has asked me to build a personalized URL system so that they can send out really short URLs in postcards to customers like this:
www.client.com/JasonSmith03
www.client.com/TonyAdams
With these URLs, I need IIS 6 to trap the incoming request and pass that “JasonSmith03” token to my database to determine which landing page to redirect them to.
I’d love to use an HttpHandler or HttpModule but they both look like they require an file extension (.aspx) in the URL. Wildcard mapping will chew up every incoming request and that’s ridiculous. ISAPI filters are just text routing files, so I can’t employ logic to call the database. According to Scott Guthrie, this would be cake if I had IIS 7, but I don’t.
Can this be done using MVC? I’ve been working with MVP for the last few years, so I haven’t done any MVC and routing. I thought I remembered that MVC has the ability to use REST-style extensionless URLs. I’d be more than happy to have these personalized URLs land on a site that’s built in MVC, if it will work.
Thank you!
You may want to look at URL Rewriting. Also the project URL RewritingNet. I've used that project before to do exactly what you need.
I'm trying to make an application that can host multiple ecommerce front ends, so I need to figure out how to route all requests to one class which then parses templates and handles all output.
So my question is then how do I route all requests to one class?
In PHP I would use mod_rewrite and have all requests go to index.php and add "main = new MainClass();", but I have no idea on how to achieve this with ASP.NET
The MVC framework isn't what I'm looking for, since I will host several domains with one system.
It sounds like what you want is an HttpModule. (Sorry for the Google link, but there's a lot about this out there and I'm not sure which is the best resource for you.)
Essentially, what an HttpModule does is intercept requests between the web server (IIS) and the application (ASP.NET).
You can use the Route class to register route handlers for all of the routes you define. Basically, you would create one instance of an implementation of IRouteHandler (or different instances of the same type) for all the permutations of the urls on your site.
Also, it should be said that following statement that you made is misguided:
The MVC framework isn't what I'm
looking for, since I will host several
domains with one system.
Any problems or limitations you would run into hosting several domains in one system with MVC will be apparent in ASP.NET as well; MVC sits on top of ASP.NET, not separate from it.