MVC AspNet - совместно использует куки FormsAuthentication между двумя приложениями на одном сервере - PullRequest
0 голосов
/ 13 марта 2019

у меня есть application_A и application_B оба с frameWork 4.6.1 на одном и том же сервере (windows Server 2016, IIS 10).

In application_A есть логин с именем пользователя и psw: в контроллере application_A я использую: FormsAuthentication.SetAuthCookie(username, false);

В web.config application_A есть:

<authentication mode="Forms">
  <forms loginUrl="/Utente/login" enableCrossAppRedirects="true" domain="192.168.20.1"  cookieless="UseCookies" timeout="2880" />
</authentication>

От application_A пользователь вошел в систему, нужно по html-ссылке перейти на application_B Так что мне нужно application_B , чтобы проверить написанное имя пользователяв cookie, поэтому я использую этот код:

string cookieName = FormsAuthentication.FormsCookieName; 
HttpCookie cookie = HttpContext.Request.Cookies[cookieName]; 
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value); 
string UserName = ticket.Name; 

В файле web.config application_B есть:

<authentication mode="Forms">
  <forms loginUrl="~/Home/Index" enableCrossAppRedirects="true" domain="192.168.20.1"   cookieless="UseCookies"  timeout="2880"/>
</authentication>

ПРОБЛЕМА заключается в том, что, когда я приедуот application_A до application_B в индексе ActionResult контроллера выдается эта ошибка:

Server Error in '/application_B' Application.

Object reference not set to an instance of an object. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error: 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace: 

[NullReferenceException: Object reference not set to an instance of an object.]
….

In application_B в строке:

string cookieName = FormsAuthentication.FormsCookieName; 

В localhost все приложения работают нормально , но когда я публикуюсь на сервере application_B дай мне ошибку.

Есть идеи?СПАСИБО

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...