Browse Source

新增授权

zhoufan 4 years ago
parent
commit
14494c7c0a

+ 34 - 0
codegit/CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/App_Start/ActionAttribute.cs

1
+using CallCenter.Utility;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Linq;
5
+using System.Web;
6
+using System.Web.Mvc;
7
+
8
+namespace CallCenterApi.Interface
9
+{
10
+    public class ActionAttribute: ActionFilterAttribute
11
+    {
12
+        public override void OnActionExecuting(ActionExecutingContext filterContext)
13
+        {
14
+            if (filterContext.Controller.ToString().ToLower() != "login")
15
+            {
16
+                try
17
+                {
18
+                    var datedue = DateTime.Parse(Configs.GetValue("datedue"));
19
+                    if (DateTime.Now > datedue)
20
+                    {
21
+                        filterContext.Result = new ContentResult() { Content = new AjaxResult { state = ResultTypes.notoken.ToString(), message = "授权过期,请联系厂家" }.ToJson() };
22
+                        return;
23
+                    }
24
+                }
25
+                catch
26
+                {
27
+                    filterContext.Result = new ContentResult() { Content = new AjaxResult { state = ResultTypes.notoken.ToString(), message = "授权过期,请联系厂家" }.ToJson() };
28
+                    return;
29
+                }
30
+            }
31
+            base.OnActionExecuting(filterContext);
32
+        }
33
+    }
34
+}

+ 1 - 0
codegit/CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/App_Start/FilterConfig.cs

6
     {
6
     {
7
         public static void RegisterGlobalFilters(GlobalFilterCollection filters)
7
         public static void RegisterGlobalFilters(GlobalFilterCollection filters)
8
         {
8
         {
9
+            filters.Add(new ActionAttribute());
9
             filters.Add(new ErrorAttribute());
10
             filters.Add(new ErrorAttribute());
10
         }
11
         }
11
     }
12
     }

+ 2 - 1
codegit/CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/CallCenterApi.Interface.csproj

16
     <RootNamespace>CallCenterApi.Interface</RootNamespace>
16
     <RootNamespace>CallCenterApi.Interface</RootNamespace>
17
     <AssemblyName>CallCenterApi.Interface</AssemblyName>
17
     <AssemblyName>CallCenterApi.Interface</AssemblyName>
18
     <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
18
     <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
19
-    <UseIISExpress>false</UseIISExpress>
19
+    <UseIISExpress>true</UseIISExpress>
20
     <IISExpressSSLPort />
20
     <IISExpressSSLPort />
21
     <IISExpressAnonymousAuthentication />
21
     <IISExpressAnonymousAuthentication />
22
     <IISExpressWindowsAuthentication />
22
     <IISExpressWindowsAuthentication />
180
     </Content>
180
     </Content>
181
   </ItemGroup>
181
   </ItemGroup>
182
   <ItemGroup>
182
   <ItemGroup>
183
+    <Compile Include="App_Start\ActionAttribute.cs" />
183
     <Compile Include="App_Start\AuthorizeAttribute.cs" />
184
     <Compile Include="App_Start\AuthorizeAttribute.cs" />
184
     <Compile Include="App_Start\FilterConfig.cs" />
185
     <Compile Include="App_Start\FilterConfig.cs" />
185
     <Compile Include="App_Start\ErrorAttribute.cs" />
186
     <Compile Include="App_Start\ErrorAttribute.cs" />