Is there a way to build urls for an action in-lining the SessionID in ASP.NET MVC ?
I need to build urls that will be used by others clients apps which need to download some kind of data but identifying the original session and I would like to have a self-contained url to do that.
Related
I have an existing CRM built in ASP.NET MVC 5 using a razorhtml front end. I would like to break off part of the project into an Angular front end with .Net Core web api backend.
Essentially when a customer hits a "next" button on a certain page, the web api would be called and return a page in angular. The customer then completes a couple pages in the angular front end, sends info to the DB via the web api, which then returns the user to the old MVC project.
The issue I'm worried about is security. How can I authenticate the customer between the two applications?
Assuming your WebAPI is hosted on the same domain as your existing MVC solution you could opt for good old cookies (mind the HttpOnly and Path properties though). Given difference in technologies this might require some sort of reverse proxying to be put in place.
Alternatively you can generate a token on MVC application side and make your angular app pass it along through request headers to your API. On server side you would either write a custom middleware to handle opaque tokens or leverage existing .Net Core Identity that supports JWT out of the box.
Given you didn't share any specifics of your environment - it's hard to say if JWT would be an overkill for your use case but hopefully this gives you some context for further exploration.
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.
I am trying to achieve the following in an MVC5 app.
In the MVC site root, the is a subdirectory "Sites" where static files live. For instance, there might be static assets (HTML, JS, CSS) for "acme" and it is located under "/Sites/acme/"
Ideally, if you hit "acme.localhost" (in my dev environment) it will serve the contents of the /Sites/acme location, defaulting to index.html. So basically everything on the subdomain of acme will be rewritten to be relative to /Sites/acme. I have the DNS side of this all sorted out.
I know the IIS URL Rewrite module is designed to do this scenario, however the catch is users can define their subdomain in my MVC app dynamically (these are currently stored in a database). I don't know what they will be, and as far as I understand editing the rewriting in web.config if I were to do it this way will cause the parent MVC application pool to recycle. This makes me think it has to be some sort of HttpHandler that looks at a cached table of possible subdomains registered in the system and rewrites accordingly.
Any thoughts or suggestions? I was thinking a HTTP module or custom Route handler but not sure how to achieve this, and am very wary of doing this in an efficient way.
Thanks
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.
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.