<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當(dāng)前位置: 首頁 - 科技 - 知識(shí)百科 - 正文

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

        來源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-27 22:36:45
        文檔

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

        .net core 1.0 實(shí)現(xiàn)單點(diǎn)登錄負(fù)載多服務(wù)器:前言 .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ù)有心
        推薦度:
        導(dǎo)讀.net core 1.0 實(shí)現(xiàn)單點(diǎn)登錄負(fù)載多服務(wù)器:前言 .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ù)有心

        前言

          .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ù)器的全部敘述,希望對大家有所幫助!

        聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

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

        .net core 1.0 實(shí)現(xiàn)單點(diǎn)登錄負(fù)載多服務(wù)器:前言 .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ù)有心
        推薦度:
        標(biāo)簽: 1.0 net 單點(diǎn)
        • 熱門焦點(diǎn)

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 中文字幕无码免费久久| 一级毛片在线免费播放| 一区二区免费视频| 亚洲国产精华液网站w| 日本免费人成视频在线观看| 亚洲精品无码Av人在线观看国产| 国产一级a毛一级a看免费视频| 中文字幕在线亚洲精品| 免费国产污网站在线观看| 亚洲成a人片77777老司机| 91精品国产免费入口| 亚洲人成网站在线观看播放动漫| 一个人在线观看视频免费| 亚洲欧洲免费无码| 亚洲第一成人影院| 国产一级婬片A视频免费观看| 亚洲AV乱码久久精品蜜桃| 五月婷婷在线免费观看| 国产精品无码亚洲精品2021| 国产精品xxxx国产喷水亚洲国产精品无码久久一区| 午夜亚洲乱码伦小说区69堂| 青青草原亚洲视频| 亚洲视频免费观看| 亚洲av无码专区首页| 国产亚洲美女精品久久久2020| 99精品一区二区免费视频| 亚洲中文无码永久免| 国产a v无码专区亚洲av| 外国成人网在线观看免费视频| 亚洲w码欧洲s码免费| 亚洲国产成人爱av在线播放| 久艹视频在线免费观看| 精品国产日韩久久亚洲| 亚洲视频在线一区二区| 亚洲黄色免费电影| 免费精品久久久久久中文字幕| 亚洲AV福利天堂一区二区三| 日韩一级视频免费观看| 久久午夜无码免费| 亚洲.国产.欧美一区二区三区| 亚洲AV一宅男色影视|