I am migrating old ASP.NET WEB Form project to Angular app with ASP.NET web API.
The requirement is to merge the newly designed angular module (say login section) with old asp.net application. The new application should be functional and work together with the old ASP.NET web form project.
Now the problem I am facing is, when I log in and try to navigate to other .aspx pages, they need some session values (which old login page used to set) to work without breaking the application.
I tried to achieve this by making HTTP call to a dummy .aspx page. I passed all the session values as query parameters and set in on the server side. It's working fine.
Is it a right approach for achieving this or is there any better way? Will there be any complication later as the application grows?
Related
I'll start by mentioning I'm new to angular and I'm new to ASP.NET. I am working on a web app that combines pdf documents into one pdf document. The tool is an angular front end and ASP.NET core back end, and it should support multiple browsers at the same time.
I have got a functioning version of the web app already going, but without the support for multiple browsers. It works as follows:
Submit pdf 1 through the angular app, that posts the pdf to the asp.net backend controller. The backend stores the pdf in a service (singleton service).
Submit pdf 2 through angular app, that posts the pdf to asp.net backend controller which stores pdf in service
Click Combine button in angular app, which posts a request to backend to combine the pdfs it has into 1, and return the newly created pdf to the angular app.
Obviously, the problem here is that I use a singleton service to persist data for the browser: If I submitted pdf1 through one browser, and then loaded up another browser and submit pdf2, and load up another browser and click the combine button, it will combine pdf 1 and 2 - which is obviously not right!
I've been looking into using session data to store the individual pdfs, but ran into a problem in that using session data in SPA applications is not advisable, and with web api is code smell. So I'm wondering what the correct way to tackle this problem is so I can go away and read up on it! How do I go about storing data per user / per browser temporarily in angular web app with asp.net backend...
I would move away from the singleton having any awareness of session/users/documents/etc and just do activities; it should be pretty stateless.
I am guessing you are persisting them in memory, which is what you mean by in the service, and that can also get tricky. Scaling could become an issue very quickly.
Perhaps there is a technical and UI solution to this? Could you persist the PDFs in a datastore, and then choose which to combine from those in the database in a separate view or page? This would be the cleanest from a data perspective.
However, if you are deadset on the same view and that view/session only being aware of what has been uploaded in that session, you would need to use some sort of identifier as J.Salas mentioned. I would still vote for moving away from storing the documents in memory, but the solution here wouldn't care either way. You can prepend the pdf identifier stored with the session ID and you know which is attached to which.
I developed a desktop C# app with WPF UI.
What would be the best way to make this as a web application (I'm very new to web devlopment)?
The initial programm gets input via the UI and than does some calculations with the API of a 3D CAD-software. Afterwards, the results are visualized in the UI dashboard.
For that process I created classes and functions that get executed when the user clicks the "Calculate" button.
Can I - broadly speaking - put the whole code behind of the "Calculate" button in a Http Get method of a controller?
And what framework would be the best fit, ASP.NET MVC or ASP.NET Web API?
Most of the ASP.NET tutorials I watched dealt mostly with CRUD operations and databases, but I don't need one in the first place.
The UI I'd like to do with vue.js and JavaScript (if that even matters).
Its unnecessary to use CRUD operations if you dont need them. You can simply to create ASP.NET MVC or ASP.NET Web Api, they are same just different boiler plate. If you create asp.net mvc, you can delete the things wich don`t needed.
You say you want Vue.js for frontend so you need web api in backend!
I thin on creation asp.net api by default you don`t have any database. So you will use only controllers and other functions wich you have
Regards
I am creating a chat bot that lives inside an IFrame on clients' sites. The bot itself uses AJAX to communicate with the .NET Core 2 server.
The problem I have is that while the session is persisted as expected when running the chat bot on its own in a browser, running it in an IFrame causes a new session to be created on each request.
Now, the reason for this is that I am using a session cookie and most browsers do not like this approach when working with Iframes. The regular ASP.NET MVC solution would be to use sessionless cookies, but as with so many other landmines in .NET CORE, cookieless sessions are not supported.
So now I'm stuck and I don't know what to do.
Simple solution: Change a div's content using the AJAX information that is returned. Don't use Iframes at all. There is no requirement to use an iframe.
You only need to use an Iframe when the content returned is a full HTML page. Based on what you said you could just return the DIV content.
To maintain persistence, just set the initial DIV content to be the session state data when the page loads.
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.
We have an Angular project we want to be independent of .NET, but it will be inside a VS project because the client is a .NET shop. Is there a way to read values from the Web.config where they can set environment variables for deployments that can go into an Angular page without it being Razor or Form based? Any type of work around?
You can expose the settings through a service that you can call via ajax from angular.
The service can be a simple http based api like asp.net web api etc.