最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

.net core 1.0 實(shí)現(xiàn)單點(diǎn)登錄負(fù)載多服務(wù)器

 更新時(shí)間:2016年07月24日 17:17:41   作者:韓天偉  
這篇文章主要介紹了.net core 1.0 實(shí)現(xiàn)單點(diǎn)登錄負(fù)載多服務(wù)器的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,感興趣的朋友可以參考下

前言

  .net core 出來有一時(shí)間了,這段時(shí)間也一直在做技術(shù)準(zhǔn)備,目前想做一個(gè)單點(diǎn)登錄(SSO)系統(tǒng),在這之前用.net時(shí)我用習(xí)慣了machineKey ,也順手在.net core 中嘗試了一上,結(jié)果發(fā)現(xiàn)不好使了,也不起作用,于是開始了網(wǎng)上學(xué)習(xí)。

實(shí)現(xiàn)方法

  功夫不負(fù)有心人,網(wǎng)上高人還是多,在github.com上面ISSUES中也有人在討論此問題,于是找到代碼嘗試,結(jié)果實(shí)現(xiàn)了。

  直接上代碼,我們需要先封裝一個(gè)XmlRepository,Key的格式如下:

 <?xml version="1.0" encoding="utf-8"?>
<key id="cbb8a41a-9ca4-4a79-a1de-d39c4e307d75" version="1">
 <creationDate>2016-07-23T10:09:49.1888876Z</creationDate>
 <activationDate>2016-07-23T10:09:49.1388521Z</activationDate>
 <expirationDate>2116-10-21T10:09:49.1388521Z</expirationDate>
 <descriptor deserializerType="Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel.AuthenticatedEncryptorDescriptorDeserializer, Microsoft.AspNetCore.DataProtection, Version=1.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60">
  <descriptor>
   <encryption algorithm="AES_256_CBC" />
   <validation algorithm="HMACSHA256" />
   <masterKey p4:requiresEncryption="true" xmlns:p4="http://schemas.asp.net/2015/03/dataProtection">
    <!-- Warning: the key below is in an unencrypted form. -->
    <value>WYgZNh/3dOKRYJ1OAhVqs56pWPMHei15Uj44DPLWbYUiCpNVEBwqDfYAUq/4jBKYrNoUbaRkGY5o/NZ6a2NTwA==</value>
   </masterKey>
  </descriptor>
 </descriptor>
</key>

XmlRepository代碼:

public class CustomFileXmlRepository : IXmlRepository
  {
    private readonly string filePath = @"C:\keys\key.xml";
    public virtual IReadOnlyCollection<XElement> GetAllElements()
    {
      return GetAllElementsCore().ToList().AsReadOnly();
    }
    private IEnumerable<XElement> GetAllElementsCore()
    {
      yield return XElement.Load(filePath);
    }
    public virtual void StoreElement(XElement element, string friendlyName)
    {
      if (element == null)
      {
        throw new ArgumentNullException(nameof(element));
      }
      StoreElementCore(element, friendlyName);
    }
    private void StoreElementCore(XElement element, string filename)
    {
    }
  }

Startup代碼:

 public class Startup
  {
    public Startup(IHostingEnvironment env)
    {
      var builder = new ConfigurationBuilder()
        .SetBasePath(env.ContentRootPath)
        .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
        .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
        .AddEnvironmentVariables();
      Configuration = builder.Build();
    }
    public IConfigurationRoot Configuration { get; }
    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
      services.AddSingleton<IXmlRepository, CustomFileXmlRepository>();
      services.AddDataProtection(configure =>
      {
        configure.ApplicationDiscriminator = "Htw.Web";
      });
      // Add framework services.
      services.AddMvc();
    }
    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
      loggerFactory.AddConsole(Configuration.GetSection("Logging"));
      loggerFactory.AddDebug();
      if (env.IsDevelopment())
      {
        app.UseDeveloperExceptionPage();
        app.UseBrowserLink();
      }
      else
      {
        app.UseExceptionHandler("/Home/Error");
      }
      app.UseStaticFiles();
      app.UseCookieAuthentication(new CookieAuthenticationOptions()
      {
        AuthenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme,
        LoginPath = new PathString("/Account/Unauthorized/"),
        AccessDeniedPath = new PathString("/Account/Forbidden/"),
        AutomaticAuthenticate = true,
        AutomaticChallenge = false,
        CookieHttpOnly = true,
        CookieName = "MyCookie",
        ExpireTimeSpan = TimeSpan.FromHours(2),
#if !DEBUG
        CookieDomain="h.cn",
#endif
        DataProtectionProvider = null
      });
      app.UseMvc(routes =>
      {
        routes.MapRoute(
          name: "default",
          template: "{controller=Home}/{action=Index}/{id?}");
      });
    }
  }

登錄代碼:

  public async void Login()
    {
      if (!HttpContext.User.Identities.Any(identity => identity.IsAuthenticated))
      {
        var user = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "bob") }, CookieAuthenticationDefaults.AuthenticationScheme));
        await HttpContext.Authentication.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, user);
        HttpContext.Response.ContentType = "text/plain";
        await HttpContext.Response.WriteAsync("Hello First timer");
      }
      else
      {
        HttpContext.Response.ContentType = "text/plain";
        await HttpContext.Response.WriteAsync("Hello old timer");
      }
    }

注意

C:\keys\key.xml 這個(gè)文件路徑可以更改,還有就是也可用共享目錄或數(shù)據(jù)庫來實(shí)現(xiàn)統(tǒng)一管理

到此可以登錄試一下。

以上所述是小編給大家介紹的.net core 1.0 實(shí)現(xiàn)單點(diǎn)登錄負(fù)載多服務(wù)器的全部敘述,希望對(duì)大家有所幫助!

相關(guān)文章

  • asp.net使用ashx生成圖形驗(yàn)證碼的方法示例

    asp.net使用ashx生成圖形驗(yàn)證碼的方法示例

    這篇文章主要介紹了asp.net使用ashx生成圖形驗(yàn)證碼的方法,結(jié)合實(shí)例形式分析了asp.net生成圖形驗(yàn)證碼的步驟、實(shí)現(xiàn)方法與相關(guān)注意事項(xiàng),需要的朋友可以參考下
    2017-07-07
  • ASP.NET?Core項(xiàng)目使用xUnit進(jìn)行單元測(cè)試

    ASP.NET?Core項(xiàng)目使用xUnit進(jìn)行單元測(cè)試

    這篇文章介紹了ASP.NET?Core項(xiàng)目使用xUnit進(jìn)行單元測(cè)試的方法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-03-03
  • .NET Core WebApi中如何實(shí)現(xiàn)多態(tài)數(shù)據(jù)綁定實(shí)例代碼

    .NET Core WebApi中如何實(shí)現(xiàn)多態(tài)數(shù)據(jù)綁定實(shí)例代碼

    這篇文章主要給大家介紹了關(guān)于.NET Core WebApi中如何實(shí)現(xiàn)多態(tài)數(shù)據(jù)綁定的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),并給出來完整的實(shí)例代碼,需要的朋友可以參考借鑒,下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-08-08
  • ASP.NET通過Remoting service上傳文件

    ASP.NET通過Remoting service上傳文件

    ASP.NET通過Remoting service上傳文件...
    2006-09-09
  • WPF使用Grid網(wǎng)格面板布局

    WPF使用Grid網(wǎng)格面板布局

    這篇文章介紹了WPF使用Grid網(wǎng)格面板布局的方法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-02-02
  • WPF的數(shù)據(jù)綁定詳細(xì)介紹

    WPF的數(shù)據(jù)綁定詳細(xì)介紹

    數(shù)據(jù)綁定:是應(yīng)用程序 UI 與業(yè)務(wù)邏輯之間建立連接的過程。 如果綁定正確設(shè)置并且數(shù)據(jù)提供正確通知,則當(dāng)數(shù)據(jù)的值發(fā)生更改時(shí),綁定到數(shù)據(jù)的視覺元素會(huì)自動(dòng)反映更改。 數(shù)據(jù)綁定可能還意味著如果視覺元素中數(shù)據(jù)的外部表現(xiàn)形式發(fā)生更改,則基礎(chǔ)數(shù)據(jù)可以自動(dòng)更新以反映更改。
    2013-03-03
  • ASP.NET中實(shí)現(xiàn)導(dǎo)出ppt文件數(shù)據(jù)的實(shí)例分享

    ASP.NET中實(shí)現(xiàn)導(dǎo)出ppt文件數(shù)據(jù)的實(shí)例分享

    這篇文章主要介紹了ASP.NET中實(shí)現(xiàn)導(dǎo)出ppt文件數(shù)據(jù)的實(shí)例分享,實(shí)例代碼用C#語言編寫,利用.NET的庫實(shí)現(xiàn)起來還是比較簡(jiǎn)潔的,需要的朋友可以參考下
    2016-02-02
  • asp.net實(shí)現(xiàn)固定GridView標(biāo)題欄的方法(凍結(jié)列功能)

    asp.net實(shí)現(xiàn)固定GridView標(biāo)題欄的方法(凍結(jié)列功能)

    這篇文章主要介紹了asp.net實(shí)現(xiàn)固定GridView標(biāo)題欄的方法,即凍結(jié)列功能,涉及GridView結(jié)合前端js操作數(shù)據(jù)顯示的相關(guān)技巧,需要的朋友可以參考下
    2016-06-06
  • .Net WebApi消息攔截器之MessageHandler的示例

    .Net WebApi消息攔截器之MessageHandler的示例

    這篇文章主要介紹了.Net WebApi消息攔截器之MessageHandler的示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-08-08
  • .NET中用ICSharpCode.TextEditor自定義代碼折疊與高亮

    .NET中用ICSharpCode.TextEditor自定義代碼折疊與高亮

    這篇文章主要給大家介紹了.NET中用ICSharpCode.TextEditor自定義代碼折疊與高亮的相關(guān)資料,文中通過示例代碼與圖片介紹的很詳細(xì),需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-02-02

最新評(píng)論

报价| 长泰县| 华蓥市| 壶关县| 阿拉善右旗| 南江县| 杂多县| 博客| 突泉县| 太仆寺旗| 黑河市| 乌兰察布市| 五河县| 襄垣县| 隆德县| 平山县| 赫章县| 扶沟县| 恩施市| 灌南县| 大兴区| 奇台县| 衡阳市| 名山县| 顺昌县| 海原县| 神农架林区| 醴陵市| 通渭县| 宣恩县| 黔东| 定边县| 四会市| 含山县| 靖边县| 清远市| 客服| 洞口县| 叶城县| 尼勒克县| 安仁县|