简体   繁体   中英

Get username client side

I have an ASP.net web app which is being hosted on a server. This web application is my Outlook add-in. I want to get the username logged in to the Outlook application. The plugin does not load when I try to use impersonation. By default, the username should not require an authorization login. I have tried many methods but without success (disable anonymous authentication and enable windows authentication, User.Identity.Name etc.)

Can anyone assist with this?

You should enable FormsAuthentication in webconfig

<authentication mode="Forms">
  <forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>

then you should set userName by

FormsAuthentication.SetAuthCookie(userName, true);

When the user submits the login form

you can reach the userName with User.Identity.Name;

You should never use OOM from web applications. Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution. Read more about that in the Considerations for server-side Automation of Office article.

You may consider using EWS or Outlook REST API, see EWS Managed API, EWS, and web services in Exchange for more information.

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