Web.config设置Form页面跳转出现问题

本文探讨了ASP.NET中登录控件及forms验证的配置方法,包括如何设置默认登录页面、验证用户身份以及通过web.config文件实现不同页面的访问权限控制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

如果你用的是ASP.net自带的登录控件,那你就在登录控件上设置一下就行了:
不知道你说的是啥意思,这边web.config设置forms验证,是指如果访问其他非登录页面(如,a.aspx)时,如果还未登录,就跳转到login.aspx中,然后在login.aspx做验证,这边除了验证用户名和密码,还需要判断是否是其他页面跳过来的,如果是的话,就redirectfrompage,具体不清楚了,反正就是formauthentication类的一些方法,就跳转了

我想说的是 无论你 进入那个页面 都要从登陆开始,
错误是设置 配置文件 出现 页面跳转问题。  

不可能到你想要的那种地址,不管你启动哪个页面
因为web.config设置forms验证,是指如果访问其他非登录页面(如,a.aspx)时,如果还未登录,就跳转到login.aspx中,然后在login.aspx做验证,这边除了验证用户名和密码,还需要判断是否是其他页面跳过来的。

随便设置一个启动页面,系统到这个地址是正确的
判断是否是其他页面跳过来的。这个能举例说明一下吗?
我设置form验证,指定了默认页 ,那肯定是 运行 一开始 就是 Login.aspx页面

格式 怎么处理啊 就算 都验证用户名和密码 然后跳转 显示多了一些字符串,导致找
这样还有谁能访问啊,二楼的说法是对的,然后这样设置权限:
你想Imprint.aspx登录访问,你可以采用<location>节点单独设置,当访问Imprint.aspx的时候,会自动重定向到 Login.aspx,并且带返回地址这里不设置 登陆页面没图片
怎么我说了很清楚了,还有人没明白,我想问的问题
路径出问题,就是9楼说的 变成那种情况,这种地址怎么处理,不可能用截取字符串的形式吧
%2fDLRWebUI%2这个是被encode了的URL,把它反编码出来看看是什么内容
笨一点的方法,假设它反编码出来是“ABC”,在所有web.config machine.config之类的设置文件内查找这个"ABC”,这样总会找到哪里设置出问题了吧?兄弟我不知道怎么反编码,有案例吗?

假设编译出来了,如你所说的 ,如abc哪有什么用?
路径一样错误 中间这节字符串 Login.aspx?ReturnUrl=%2fDLRWebUI%2是自动生成的
换成 mode=Windows 就不会出现这字符串,这样设置项目没意义了

你deny了登录用户,所以登录完毕后还是不让访问啊,还是要返回去的,
在.NET中,值传递是ref和out,ref在使用前必须要赋值,而out使用前不需要赋值
带参数的构造函数只是生成了一个临时对象,在类外的某个地方调用则返回这个由构造函数生成的临时对象。既然是临时的说明是引用类型!构造函数有四种!
想在我想实现treeview的拖拽功能,我也在网上查了一些代码,但是,我知道怎么添加事件,如, 1.ItemDrag事件(当用户开始拖动节点时发生。)2.DragEnter事件(在将对象拖入控件的边界时发生。)3.DragDrop事件(在完成拖放操作时发生。)
小弟刚学习c#,忘各位大侠们指点,希望给我详细的过程,让我深入下学习 ,小弟感激不尽!!
可以在两台连着的电脑,也就是局域网只能使用的,能禁止局域网另一台电脑的部分软件得正常运行(比如说QQ 之类的),还能禁止别人上网的(或者是能禁止打开网页的软件),

这个要求不光要软件,还要你网络结构的支持网关软件你找找看

Accounts中可设定用户和组信息,如果你对上网的管理还涉及到人的话,就要认真设置这一项了,因为前面的Advance/Packet Filter是设置计算机上网管理(IP),这台机子不能上,人家换台机子上,而如果设置了Accounts的话,那就上网要密码了!对于那些上班8小时就上网7小时的人来讲,这就是“杀手锏”了。
  SF哥,有没有国语的,外语实在太烂。。。。。而且,这个这款软件好像只可以控制别人什么时候可以上网,但是不能控制别人不能上哪一款软件是吧? 
来源:nba直播

package com.kucun.Config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.access.AccessDeniedHandler; // 2. 基础安全配置 @Configuration @EnableWebSecurity // 启用Web安全功能 public class SecurityConfig extends WebSecurityConfigurerAdapter{ /** * 核心安全过滤器链配置 * @param http HTTP安全构建器 * @return 安全过滤器链 * @throws Exception 配置异常 * * █ 配置逻辑说明: * 1. authorizeHttpRequests: 定义访问控制规则 * 2. formLogin: 配置表单登录 * 3. logout: 配置注销行为 * 4. exceptionHandling: 处理权限异常[^3] */ @Override public void configure(HttpSecurity http) throws Exception { http .authorizeRequests(auth -> auth // 按从具体到泛型的顺序配置 .antMatchers("/login.html").permitAll() .antMatchers(HttpMethod.POST, "/users/login").permitAll() .antMatchers("/users/guanli/**").hasRole("ADMIN") .antMatchers("/js/**", "/css/**", "/fonts/**", "/images/**").permitAll() .anyRequest().authenticated() ) .formLogin(form -> form .loginPage("/login.html") .loginProcessingUrl("/users/login") .defaultSuccessUrl("/index.html", true) .failureUrl("/login.html?error=true") ) .logout(logout -> logout .logoutUrl("/logout") .logoutSuccessUrl("/login.html") ) .csrf(csrf -> csrf .ignoringAntMatchers("/users/login") // 禁用CSRF保护 ) .headers(headers -> headers .frameOptions().sameOrigin() ) // 异常处理 .exceptionHandling(ex -> ex .accessDeniedPage("/error/403") // 权限不足跳转页面[^3] ); //return http.build(); } /** * 密码编码器(必须配置) * 使用BCrypt强哈希算法加密 */ @Bean public PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } @Bean public AccessDeniedHandler accessDeniedHandler() { System.out.println("0000"); return (request, response, accessDeniedException) -> { if (!response.isCommitted()) { request.getRequestDispatcher("/error/403").forward(request, response); } }; } }
最新发布
05-29
package com.lh.config; import com.lh.Service.CustomUserDetailsService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.web.SecurityFilterChain; @Configuration @EnableWebSecurity public class SecurityConfig { @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { http .authorizeHttpRequests(auth -> auth .requestMatchers("/login").permitAll() // 允许所有用户访问登录页面 .requestMatchers("/admin/**").hasRole("admin") // 管理员页面,只有ADMIN角色可以访问 .requestMatchers("/user/**").hasRole("user") // 用户页面,只有USER角色可以访问 .anyRequest().authenticated() // 其他请求都需要认证 ) .formLogin(form -> form .loginPage("/login") // 指定自定义登录页面 .loginProcessingUrl("/login") // 指定登录表单提交处理URL .defaultSuccessUrl("/index",true) // 登录成功后跳转的URL .failureUrl("/login?error") // 登录失败后跳转的URL .usernameParameter("username") // 表单中用户名的参数名 .passwordParameter("password") // 表单中密码的参数名 ) .logout(logout -> logout .logoutUrl("/logout") // 注销请求的URL .logoutSuccessUrl("/login") // 注销成功后跳转的URL ) .csrf(csrf -> csrf.disable()); // 禁用CSRF保护 return http.build(); } @Bean public UserDetailsService userDetailsService() { return new CustomUserDetailsService(); } @Bean public PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } }这是配置文件,在loadUserByUsername方法内添加日志输出,请求没有触发
05-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值