如何设置ASP.NET Web API2默认启动页面为登录界面?
- 内容介绍
- 文章标签
- 相关推荐
本文共计215个文字,预计阅读时间需要1分钟。
1. 在Global.asax文件中添加Application_BeginRequest方法,如下所示:csharppublic class WebApiApplication : HttpApplication{ protected void Application_Start() { log4net.Config.XmlConfigurator.Configure(new FileInfo(Server.MapPath(~/log4net.config))); }}
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开发
到此这篇关于asp.netwebapi2设置默认启动登录页面的文章就介绍到这了,更多相关asp.netwebapi2默认登录页面内容请搜索易盾网络以前的文章或继续浏览下面的相关文章希望大家以后多多支持易盾网络!
本文共计215个文字,预计阅读时间需要1分钟。
1. 在Global.asax文件中添加Application_BeginRequest方法,如下所示:csharppublic class WebApiApplication : HttpApplication{ protected void Application_Start() { log4net.Config.XmlConfigurator.Configure(new FileInfo(Server.MapPath(~/log4net.config))); }}
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开发
到此这篇关于asp.netwebapi2设置默认启动登录页面的文章就介绍到这了,更多相关asp.netwebapi2默认登录页面内容请搜索易盾网络以前的文章或继续浏览下面的相关文章希望大家以后多多支持易盾网络!

