asp.net web api2默认登录页面

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

asp.net web api2默认登录页面

小小鱼34309335   2022-09-29 我要评论

1.在Global.asax文件中添加Application_BeginRequest方法,如下如所示:

public class WebApiApplication : HttpApplication
{
    protected void Application_Start()
    {
        log4net.Config.XmlConfigurator.Configure(new FileInfo(Server.MapPath("~/Web.config")));
        AreaRegistration.RegisterAllAreas();
        GlobalConfiguration.Configure(WebApiConfig.Register);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
    }
    
    
    protected void Application_BeginRequest(object sender, EventArgs e)
    {
        if (Context.Request.FilePath == "/") 
            Context.RewritePath("home/page/login.html");
    }
}

静态页面的目录结构如下所示:

2.等启动项目后,到了登录页,有可能会发现静态资源,如图片,css,js文件全部加载失败,这个时候需要修改一下路径,如下所示:

登录成功跳转的页面也要注意下。

备注:项目使用rider2022.2.3开发 

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们