-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathGlobal.asax.cs
43 lines (39 loc) · 1.36 KB
/
Global.asax.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using NetSSL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace NetSSL.Web
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
ValueProviderFactories.Factories.Remove(ValueProviderFactories.Factories.OfType<JsonValueProviderFactory>().FirstOrDefault());//移除默认的JsonValueProviderFactory
ValueProviderFactories.Factories.Add(new NetSSLJsonVauleProviderFactory());//加上SSL的JsonValueProviderFactory
}
protected void Application_Error(object sender, EventArgs e)
{
var ex = Server.GetLastError();
if (ex is NetSSLException)
{
LogError(ex as NetSSLException);
}
Server.ClearError();
}
private void LogError(NetSSLException ex)
{
if (Response == null)
return;
Server.ClearError();
Response.StatusCode = 200;
Response.TrySkipIisCustomErrors = true;
string exMsg = JsonHelper.Serialize(JResult.Error(ex.Message, ex.ExceptionCode));
Response.Write(exMsg);
}
}
}