ASP.Net MVC Allow Subdomains in URL - c#

This is a different question than the one here: Is it possible to make an ASP.NET MVC route based on a subdomain?
I'm not looking to reroute based on subdomain, I just want to be able to include a subdomain and end up in the same place.
user1.mydomain.com should go to the same place as user2.mydomain.com
I can pluck the subdomain from the request to use it.
Currently a request to foo.localhost returns a 404 error.
Help would be much appreciated.

You can do this at the web host level. It's called site bindings in IIS, I'm not sure what Apache calls it.

Related

Call external Web API from MVC project with windows Auth

I have an existing MVC application that I inherited from someone else.
I am now trying to take some of the API calls from the old application and move them into a new application.
The problem is, when the MVC application tries to call the API calls in the new application, it gets a 401.2 (unauthorised) response.
I have read that 401.2 means that the front end and the back end are using different authentication protocols, which would make sense to me.
Here is a snip of the response headers for the account call in the new application:
and here is a snip of the same response headers when calling the same API from the old application:
This looks to me like they are using different protocols - am I correct? The main difference seems to be the 'WWW-Authenticate:Negotiate' on the failed request - but I do not know how I can fix this?
If so, can anyone advise what I need to change in my MVC project to make it use the Auth type of the first project?
Both aps use the same database if that is any help?
I know this question is a bit vague, but I have no idea where to look to fix this.
Any help would be greatly appreciated...
You would need a Single Sign-on to maintain your credentials through different apps, you could:
Use Identity Server 4 or Identity Server 3 To generate token credentials for you WEB API Projects.
MVC
JS
User Forms authentication on your mvc Projects:
Example
Use cookie based Authorization:
Cookie authorization with OWIN
I recommend Using Identity Server.

c# web api 2 - any way to wrap all routes for "site is down"?

The high level problem I'm trying to solve:
Given our design of
- c# web api to modify entities and retrieve view models
- react SPA frontend
I want to be able to conditionally turn the c# web api "off" and tell the SPA the "site is down for maintenance". The purpose for this is to prevent odd errors in the client in the case someone is using the site during the transition.
The initial idea I had to solve this was to wrap each call in a web.config check to see if the site is down, and if so, return a hard-coded error response which the frontend knows what to do with. However the cleanest approach I can think of is to inject a service into each web api controller and invoke it at the beginning of each route. I was instead hoping for a way to avoid this boilerplate.
In node I would decorate all the routes in a wrapper function that does this. C# is a little more foreign to me.
If you host your WebAPI as its own ASP.NET site then you can place an app_offline.htm file in the IIS root, and it will automatically go into maintenance mode.
ASP.NET will immediately server 503's and the page contents for all new requests, while allowing existing requests to complete.

Workflow required to support vanity urls in iis and asp.net

Can someone please walk me through the workflow required to support vanity URLs using IIS 7 and ASP.NET 4.0? What I want to do is be able to handle a request from the browser such as http://john.mysite.com and have it go to and execute my page at http://www.mysite.com/mypage.aspx?id=3. Of course the id would change depending on the url. http://zack.mysite.com might go to http://www.mysite.com/mypage.aspx?id=4.
What I am thinking is I need a database that holds the id's for zack and john and then I would implement a URL rewriter that would rewrite the url to the actual page (e.g. http://www.mysite.com/mypage.aspx?id=4).
Can someone please tell me if I am on the right track here?
Yes I do believe this can be achieved using the IIS URL rewrite module. Note that ASP.NET does support some custom routing too.

Extensionless Personalized URLs - MVC?

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.

Route all page requests to one class in ASP.NET

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.

Categories

Resources