增加SSO逻辑

This commit is contained in:
yubaolee
2016-07-08 11:28:38 +08:00
parent d3c98fdc87
commit 032bc20e1e
112 changed files with 52068 additions and 178 deletions

View File

@@ -1,59 +0,0 @@
using System;
using System.Collections.Generic;
namespace Infrastructure
{
public class ControlHelper
{
/// <summary>
/// 根据集合得到下拉框
/// </summary>
/// <typeparam name="T">实体对象</typeparam>
/// <param name="rList">实体集合</param>
/// <param name="id">下拉框的id</param>
/// <param name="valFiled">值 字段名</param>
/// <param name="nameFiled">文本 字段名</param>
/// <param name="selected">需要选中的值</param>
/// <param name="css">样式名称</param>
/// <returns></returns>
public static string GetDropDownByList<T>(List<T> rList, string id, string valFiled, string nameFiled, string selected = "0", string css = "")
{
string str = " <select id='" + id + "' name='" + id + "' class='" + css + "'>";
foreach (var item in rList)
{
string value = item.GetType().GetProperty(valFiled).GetValue(item, null).ToString();
string text = item.GetType().GetProperty(nameFiled).GetValue(item, null).ToString();
str += "<option ";
if (value.Equals(selected)) str += " selected='selected' ";
str += " value='" + value + "'>" + text + "</option>";
}
if (rList.Count == 0) str += "<option value='没有数据'>没有数据</option>";
str += " </select>";
return str;
}
/// <summary>
/// 根据枚举得到下拉框
/// </summary>
/// <typeparam name="type">枚举对象</typeparam>
/// <param name="id">下拉框的id</param>
/// <param name="selected">需要选中的值</param>
/// <param name="css">样式名称</param>
/// <returns></returns>
public static string GetDropDownByEnum(Type type, string id, string selected = "", string css = "")
{
string str = " <select id='" + id + "' name='" + id + "' class='" + css + "'>";
str += "<option value=''>全部</option>";
foreach (int item in System.Enum.GetValues(type))
{
string value = item.ToString();
string text = System.Enum.GetName(type, item);
str += "<option ";
if (value.Equals(selected)) str += " selected='selected' ";
str += " value='" + value + "'>" + text + "</option>";
}
str += " </select>";
return str;
}
}
}

View File

@@ -13,7 +13,7 @@
using System;
using System.Web;
namespace Infrastructure.Helper
namespace Infrastructure
{
/// <summary>
/// Cookie帮助类
@@ -68,5 +68,45 @@ namespace Infrastructure.Helper
}
return "";
}
/// <summary>
/// Get cookie expiry date that was set in the cookie value
/// </summary>
/// <param name="cookie"></param>
/// <returns></returns>
public static DateTime GetExpirationDate(HttpCookie cookie)
{
if (String.IsNullOrEmpty(cookie.Value))
{
return DateTime.MinValue;
}
string strDateTime = cookie.Value.Substring(cookie.Value.IndexOf("|") + 1);
return Convert.ToDateTime(strDateTime);
}
/// <summary>
/// Set cookie value using the token and the expiry date
/// </summary>
/// <param name="value"></param>
/// <param name="minutes"></param>
/// <returns></returns>
public static string BuildCookueValue(string value, int minutes)
{
return String.Format("{0}|{1}", value, DateTime.Now.AddMinutes(minutes).ToString());
}
/// <summary>
/// Reads cookie value from the cookie
/// </summary>
/// <param name="cookie"></param>
/// <returns></returns>
public static string GetCookieValue(HttpCookie cookie)
{
if (String.IsNullOrEmpty(cookie.Value))
{
return cookie.Value;
}
return cookie.Value.Substring(0, cookie.Value.IndexOf("|"));
}
}
}

View File

@@ -13,11 +13,17 @@
// ***********************************************************************
using System;
using System.Security.Cryptography;
namespace Infrastructure
{
public class GenerateId
{
public static string GetGuidHash()
{
return Guid.NewGuid().ToString().GetHashCode().ToString("x");
}
/// <summary>
/// 生成一个长整型可以转成19字节长的字符串
/// </summary>
@@ -40,7 +46,16 @@ namespace Infrastructure
i *= ((int)b + 1);
}
return string.Format("{0:x}", i - DateTime.Now.Ticks);
return String.Format("{0:x}", i - DateTime.Now.Ticks);
}
/// <summary>
/// 创建11位的英文与数字组合
/// </summary>
/// <returns>System.String.</returns>
public static string ShortStr()
{
return Convert(GenerateLong());
}
/// <summary>
@@ -55,6 +70,8 @@ namespace Infrastructure
return strDateTimeNumber + strRandomResult;
}
#region private
/// <summary>
/// 参考msdn上的RNGCryptoServiceProvider例子
/// </summary>
@@ -66,46 +83,44 @@ namespace Infrastructure
// Create a byte array to hold the random value.
byte[] randomNumber = new byte[length];
// Create a new instance of the RNGCryptoServiceProvider.
System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
// Fill the array with a random value.
rng.GetBytes(randomNumber);
// Convert the byte to an uint value to make the modulus operation easier.
uint randomResult = 0x0;
for (int i = 0; i < length; i++)
{
randomResult |= ((uint)randomNumber[i] << ((length - 1 - i) * 8));
randomResult |= ((uint) randomNumber[i] << ((length - 1 - i)*8));
}
return (int)(randomResult % numSeeds) + 1;
return (int) (randomResult%numSeeds) + 1;
}
/// <summary>
/// 创建11位的英文与数字组合
/// </summary>
/// <returns>System.String.</returns>
public static string ShortStr()
{
return Convert(GenerateLong());
}
static string Seq = "s9LFkgy5RovixI1aOf8UhdY3r4DMplQZJXPqebE0WSjBn7wVzmN2Gc6THCAKut";
/// <summary>
/// 10进制转换为62进制
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
private static string Convert(long id)
private static string Convert(long id)
{
if (id < 62)
{
return Seq[(int)id].ToString();
return Seq[(int) id].ToString();
}
int y = (int)(id % 62);
long x = (long)(id / 62);
int y = (int) (id%62);
long x = (long) (id/62);
return Convert(x) + Seq[y];
}
#endregion
}
}

View File

@@ -35,15 +35,29 @@
<Reference Include="AutoMapper">
<HintPath>..\packages\AutoMapper.4.1.0\lib\net45\AutoMapper.dll</HintPath>
</Reference>
<Reference Include="Enyim.Caching, Version=2.12.0.0, Culture=neutral, PublicKeyToken=cec98615db04012e, processorArchitecture=MSIL">
<HintPath>..\packages\EnyimMemcached.2.12\lib\net35\Enyim.Caching.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="log4net">
<HintPath>..\packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
@@ -53,12 +67,15 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AutoMapperExt.cs" />
<Compile Include="ControlHelper.cs" />
<Compile Include="Cache\CacheContext.cs" />
<Compile Include="Cache\EnyimMemcachedContext.cs" />
<Compile Include="Cache\SessionContext.cs" />
<Compile Include="CookieHelper.cs" />
<Compile Include="DynamicLinq.cs" />
<Compile Include="DynamicQueryable.cs" />
<Compile Include="Filter.cs" />
<Compile Include="GenerateId.cs" />
<Compile Include="HttpHelper.cs" />
<Compile Include="JsonConverter.cs" />
<Compile Include="JsonHelper.cs" />
<Compile Include="LogHelper.cs" />
@@ -67,12 +84,14 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Response.cs" />
<Compile Include="SessionHelper.cs" />
<Compile Include="UriUtil.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<!-- <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>

View File

@@ -15,7 +15,7 @@
using System;
using System.Web;
namespace Infrastructure.Helper
namespace Infrastructure
{
/// <summary>
/// Session 帮助类

View File

@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AutoMapper" version="4.1.0" targetFramework="net45" />
<package id="EnyimMemcached" version="2.12" targetFramework="net45" />
<package id="log4net" version="2.0.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
</packages>