• nopcommerce +autofac +owin +webapi


     public partial class Startup
        {
            public void Configuration(IAppBuilder app)
            {
                HttpConfiguration config = new HttpConfiguration();
                // Web API 路由
                config.MapHttpAttributeRoutes();
                config.Routes.MapHttpRoute(
                    name: "DefaultApi",
                    routeTemplate: "api/{controller}/{id}/{namespaces}",
                    defaults: new { id = RouteParameter.Optional, namespaces = new[] { "Nop.API.ApiControllers" } }
                );
    
               
                var builder = new ContainerBuilder();
                // We have to register services specifically for the API calls!
                builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
                
                //Update existing, don't create a new container
                builder.Update(EngineContext.Current.ContainerManager.Container);
    
                //Feed the current container to the AutofacWebApiDependencyResolver
                var resolver = new AutofacWebApiDependencyResolver(EngineContext.Current.ContainerManager.Container);
                config.DependencyResolver = resolver;
    
    
                // enable API versioning
                //config.Services.Replace(typeof(IApiExplorer), new VersionedApiExplorer(GlobalConfiguration.Configuration));
                //config.Services.Replace(typeof(IHttpControllerSelector), new RouteVersionedControllerSelector(GlobalConfiguration.Configuration));
    
                //exception logger 
                //config.Services.Add(typeof(IExceptionLogger), new SimpleExceptionLogger());
                //exception handler
                //config.Services.Replace(typeof(IExceptionHandler), new GlobalExceptionHandler());
    
    
                //we will get JSON by default, but it will still allow you to return XML if you pass text/xml as the request Accept header
                //var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml");
                //config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType);
                config.EnsureInitialized();
                //FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
                //GlobalConfiguration.Configuration.EnsureInitialized();
               
    
                app.UseAutofacMiddleware(EngineContext.Current.ContainerManager.Container);
                app.UseAutofacWebApi(config);
                app.UseWebApi(config);
                
                //ConfigureAuth(app);
    
            }
    
    
    
            public void ConfigureAuth(IAppBuilder app)
            {
                // 针对基于 OAuth 的流配置应用程序  
                var OAuthOptions = new OAuthAuthorizationServerOptions
                {
                    TokenEndpointPath = new PathString("/Token"),
                    //Provider = new NopAuthorizationServerProvider(),
                    AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
                    //在生产模式下设 AllowInsecureHttp = false  
                    /*AllowInsecureHttp设置整个通信环境是否启用ssl, 
                    不仅是OAuth服务端,也包含Client端, 
                    当设置为false时,若登记的Client端重定向url未采用https,则不重定向*/
                    AllowInsecureHttp = true,
    
                };
    
                // 使应用程序可以使用不记名令牌来验证用户身份  
                app.UseOAuthBearerTokens(OAuthOptions);
            }
        }

     http://www.nopchina.net/post/nopcommerce-plugin-webapi.html

  • 相关阅读:
    IIS 7.0 下 httpMoudle 失效的问题
    iis 管理员执行 aspnet_iis.exe
    java script 闭包
    c# 多语言实现 与 InitializeCulture
    谈 IIS7.5 Asp.Net模拟用户
    oledb 写入 office2010 以及发布到iis 遇到的奇怪问题总结
    DataTableToExcel
    下拉加载数据
    简单使用TFS管理源代码
    a span做成按钮样式不选中文字
  • 原文地址:https://www.cnblogs.com/tgdjw/p/5825745.html
Copyright © 2020-2023  润新知