2017-04-06 13 views
5

के बाद एमवीसी क्लाइंट को रीडायरेक्ट करें मैं लॉगऑन काम नहीं कर रहा हूं, तो मैं IdenetityServer4 का उपयोग कर रहा हूं और एमवीसी क्लाइंट को रीडायरेक्ट कर रहा हूं। बाद मेरी MVC ग्राहक नियंत्रक लॉगआउट कार्रवाई है:पहचान सर्वर 4 - लॉगआउट

public async Task Logout() 
{ 
    await HttpContext.Authentication.SignOutAsync("Cookies"); 
    await HttpContext.Authentication.SignOutAsync("oidc"); 
} 

के बाद पहचान सर्वर 4 होस्ट कॉन्फ़िग फ़ाइल है।

public static IEnumerable<Client> GetClients() 
{ 
    return new List<Client> 
    { 
     // other clients omitted... 

     // OpenID Connect implicit flow client (MVC) 
     new Client 
     { 
      ClientId = "mvc", 
      ClientName = "MVC Client", 
      AllowedGrantTypes = GrantTypes.Implicit, 

      // where to redirect to after login 
      RedirectUris = { "http://localhost:58422/signin-oidc" }, 

      // where to redirect to after logout 
      PostLogoutRedirectUris = { "http://localhost:58422/signout-callback-oidc" }, 

      AllowedScopes = new List<string> 
      { 
       IdentityServerConstants.StandardScopes.OpenId, 
       IdentityServerConstants.StandardScopes.Profile 
      } 
     } 
    }; 
} 

मैं उपयोगकर्ता वापस MVC ग्राहक के लिए IdentityServer से लॉग आउट हो जाने पर पुन: निर्देशित करना चाहते हैं। अभी उपयोगकर्ता को एमवीसी साइट पर रीडायरेक्ट करने के लिए नीचे दी गई छवि में लिंक शो पर क्लिक करना है, लेकिन मुझे लगता है कि उपयोगकर्ता को स्वचालित रूप से एमवीसी क्लाइंट पर रीडायरेक्ट किया जाना चाहिए।

enter image description here

+1

शेयर त्रुटि कृपया और अतिरिक्त लॉग। – Lutando

उत्तर

5

अपने Config.cs में या MVC नियंत्रक में कोई समस्या नहीं है।

जाओ अपने IdentityServer4 आवेदन तो AccountController के लॉगआउट [HttpPost] विधि के अंदर, निम्न परिवर्तन करना है:

public async Task<IActionResult> Logout(LogoutViewModel model) 
{ 
    ...  
    //return View("LoggedOut", vm); 
    return Redirect(vm.PostLogoutRedirectUri); 
} 

यह (अपने मामले में) वापस MVC आवेदन करने के लिए उपयोगकर्ता अनुप्रेषित करेगा।

यह करने के लिए एक बेहतर तरीका है: इस प्रकार आप AccountOptions.cs से इन विकल्पों को सेट कर सकते हैं:

public static bool ShowLogoutPrompt = false; 
public static bool AutomaticRedirectAfterSignOut = true; 
+0

मेरे पास एक ही क्लाइंट कॉन्फ़िगरेशन है @Sandeep के रूप में PostLogoutRedirectUris सहित, लेकिन जब मैं डीबग मोड में प्रोजेक्ट शुरू करता हूं तो मैं देख सकता हूं कि vm.PostLogoutRedirectUri शून्य है। कोई विचार क्यों? – CodeEngine

+0

और स्पष्टीकरण की आवश्यकता है। क्या आप डिबगिंग करते समय अपने क्लाइंट से लॉग आउट करने का प्रयास कर रहे थे? क्योंकि, vm.PostLogoutRedirectUri सेट किया जाएगा जब किसी कॉन्फ़िगर किए गए क्लाइंट से लॉग आउट अनुरोध प्राप्त होता है। – Akhilesh

संबंधित मुद्दे