Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
拒绝使用Identity Framework和Owin在Asp.net Web窗体上未登录的所有页面_Asp.net_Webforms_Asp.net Identity_Owin - Fatal编程技术网

拒绝使用Identity Framework和Owin在Asp.net Web窗体上未登录的所有页面

拒绝使用Identity Framework和Owin在Asp.net Web窗体上未登录的所有页面,asp.net,webforms,asp.net-identity,owin,Asp.net,Webforms,Asp.net Identity,Owin,如何使用identity和owin设置web表单应用程序,以拒绝除登录之外的所有页面 web.config中的此配置不适用于我: <system.web> <authorization> <deny users="*"/> </authorization> <authentication mode="None"/> 错误消息:请求过滤模块配置为拒绝查询字符串过长的请求 OWIN启动类: p

如何使用identity和owin设置web表单应用程序,以拒绝除登录之外的所有页面

web.config中的此配置不适用于我:

 <system.web>
    <authorization>
      <deny users="*"/>
    </authorization>
    <authentication mode="None"/> 

错误消息:请求过滤模块配置为拒绝查询字符串过长的请求

OWIN启动类:

 public void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context, user manager and signin manager to use a single instance per request
            app.CreatePerOwinContext(ApplicationDbContext.Create);
            app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);

            // Enable the application to use a cookie to store information for the signed in user
            // and to use a cookie to temporarily store information about a user logging in with a third party login provider
            // Configure the sign in cookie
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login"),
                Provider = new CookieAuthenticationProvider
                {
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, Usuario>(
                        validateInterval: TimeSpan.FromMinutes(0),
                        regenerateIdentity: (manager, user) => manager.GenerateUserIdentityAsync(user))
                }
            });
public void ConfigureAuth(IAppBuilder应用程序)
{
//将数据库上下文、用户管理器和登录管理器配置为每个请求使用一个实例
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext(ApplicationUserManager.Create);
app.CreatePerOwinContext(ApplicationSignInManager.Create);
//使应用程序能够使用cookie存储登录用户的信息
//以及使用cookie临时存储用户登录第三方登录提供商的信息
//配置登录cookie
app.UseCookieAuthentication(新的CookieAuthenticationOptions
{
AuthenticationType=DefaultAuthenticationTypes.ApplicationOkie,
LoginPath=新路径字符串(“/Account/Login”),
Provider=新CookieAuthenticationProvider
{
OnValidateIdentity=SecurityStampValidator.OnValidateIdentity(
validateInterval:TimeSpan.FromMinutes(0),
regenerateIdentity:(管理者,用户)=>manager.GenerateUserIdentityAsync(用户))
}
});
项目结构

编辑:

在帐户文件夹内的web.config上有此配置

<configuration>

  <location path="Manage.aspx">
    <system.web>
      <authorization>
        <allow users="?"/>
      </authorization>
    </system.web>
  </location>

</configuration>

这适用于Manage.aspx页面

我不希望对每个页面都这样做。我希望将其放入站点的global web.config。

if(User.Identity.IsAuthenticated) { 继续关注 } 其他的 { 转学
}

您可以在web.config中对其进行如下配置:

<system.web>
    <authorization>
        <deny users="?"/>
        <allow users="*"/>
    </authorization>
</system.web>
<location path="Login.aspx">
    <system.web>
        <authorization>
            <allow users="*" />
        </authorization>
    </system.web>
</location>

编辑:添加了超长请求字符串的配置

如果您的请求太长,您可以在web.config中添加以下内容以解决此问题:

<system.webServer>
  <security>
     <requestFiltering>
         <requestLimits maxQueryString="nnn"/>
     </requestFiltering>
  </security>
</system.webServer>


我希望现在就可以解决这个问题。

这是asp.net identity和FriendlyURL中的一个错误


我在
Web.config
上做了很多实验,但总是出现前面所述的错误。然后我放弃了它,只是在
Global.asax

protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
  string cTheFile = HttpContext.Current.Request.Path;
  if (!cTheFile.EndsWith("Login"))
  {
    if (HttpContext.Current.User == null || 
      HttpContext.Current.User.Identity == null || 
      !HttpContext.Current.User.Identity.IsAuthenticated)
    {
      Response.Redirect("~/Account/Login", true);
      Response.End();
      return;
    }
  }
}

这对我来说效果很好,尽管我不确定这是否是一个最佳解决方案。

我认为没有必要进行硬代码验证。此配置不起作用。错误消息:请求筛选模块配置为拒绝查询字符串过长的请求。我认为这不必要。url不应该太长。2016…仍然是一个bug…您的链接似乎已断开。