简体   繁体   中英

Loading user info from DB with web service

I'm creating a website wit ASP.net where the data is coming from a database. However, the website does not access the database directly but through a web service.

Data stream:

DB >> Web service >> Web site

The logging and the user information retrieval works fine.

Once the user is logged, using the FormsAuthentication.RedirectFromLoginPage , the user can access the restricted pages and the username is accessible using User.Identity.Name from the http context.

The problem is when I restart the app, I guess the username is saved in the cookies and I am already logged in. That is fine but I only have the user name, not the full user info that I need from the start.

When logged in, I created an object with all the info, getting the data from the DB through the web service.

Is there a way to retrieve that same info from the DB using the web service, but at load time?

My idea is to get the user id and authentication token saved in the cookie and call the web service and recreate the user info object.

Is there a better way?

I already tried that solution using Session_Start or even Application_BeginRequest but due to the call to the web service being asynchronous, I get an error.

Speaking of asynchronous, how can I make sure I get the user info recreated before the master page is loaded? (I need the user info so I can know what to show on the page or not).

I hope it is clear. If not, please let me know.

Thank you,

Of course, after spending the whole day working on it and finally ask you for advice, I found a way to make it work.

I'm redirecting to the login page that will check the cookie and get the user info is it does not have it in the cache already.

If it's not available from the DB, it would show the login page.

I'm not sure it is the best way to go so I'll wait for your replies ;-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM