有没有办法在 ASP.NET Web 表单页面应用程序中使用 Auth0?

发布于 2025-01-10 21:24:38 字数 284 浏览 2 评论 0原文

我试图在 Web 表单页面 (aspx) 应用程序和链接 https: //auth0.com/docs/quickstart/webapp/aspnet 似乎已被删除,因为它重定向到常规 Web 应用程序的其他快速入门。我尝试使用 ASP.NET (OWIN) 即 MVC 文档,但这似乎不起作用。所以我的问题是,是否仍然可以在传统的 Web 表单应用程序中实现 Auth0?

I was trying to implement Auth0 in the web forms page (aspx) application and the documentation on link https://auth0.com/docs/quickstart/webapp/aspnet seems to be deleted as it redirects to other quickstarts for Regular Web Apps. I tried using ASP.NET (OWIN) i.e. MVC documentation but that doesn't seem to be working. So my question is that is it still possible to implement Auth0 in traditional webforms apps?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帥小哥 2025-01-17 21:24:38

是的,你可以,但你必须借助 asp.net MVC。

Asp.NET MVC 构建在 ASP.NET 之上,因此我们可以轻松集成 Webform 应用程序并利用 MVC 控制器和路由配置类的优势。

为此,您需要包含以下软件包。

 //for mvc
Microsoft.AspNet.mvc

//for owin
Microsoft.Owin.Host.SystemWeb
Microsoft.AspNet.Identity.Core
Microsoft.Owin.Security.Cookies

在根级别创建两个文件夹,

    a. App_Start and,
    b. Controllers same as an MVC project.

文件夹的文件内容应如下所示:

1. App_Start folder - add the below class files.
 a. RouteConfig.cs - 
      Here we will set up the default route to Home/index. Thus, any 
        redirection (“/”) or http://localhost, will redirect to the 
       home/index, which will in turn call the authentication method.

 b. Startup.cs - It will be the Owin startup class. 
    This can also be used to write custom middleware.

2. Controllers - add the below controllers

    a. Home - decorate *[Authorize]* attribute at controller 
       level. Add a default index action. Call the action that will 
       implement authentication logic. In this case, AccountController.

    b. Account - where you will write code for authentication.

每当会话结束时,您可以通过编写以下代码从任何 .aspx.cs 页面重定向到 Home/index:

protected void Page_Load(object sender, EventArgs e)
   {
     if (Session["CurrentUser"] == null) {        
         Response.Redirect("/");
     }

   // other logics
   // ---
   // ---

   
  }

Yes, you can but you have to take the help of asp.net MVC.

Asp.NET MVC is built on top of ASP.NET so, we can easily integrate webform applications and take the benfit of MVC controllers and route config classes.

For this, you need to include the below packages.

 //for mvc
Microsoft.AspNet.mvc

//for owin
Microsoft.Owin.Host.SystemWeb
Microsoft.AspNet.Identity.Core
Microsoft.Owin.Security.Cookies

Create two folders at root level,

    a. App_Start and,
    b. Controllers same as an MVC project.

The file content of the folder should be as follow:

1. App_Start folder - add the below class files.
 a. RouteConfig.cs - 
      Here we will set up the default route to Home/index. Thus, any 
        redirection (“/”) or http://localhost, will redirect to the 
       home/index, which will in turn call the authentication method.

 b. Startup.cs - It will be the Owin startup class. 
    This can also be used to write custom middleware.

2. Controllers - add the below controllers

    a. Home - decorate *[Authorize]* attribute at controller 
       level. Add a default index action. Call the action that will 
       implement authentication logic. In this case, AccountController.

    b. Account - where you will write code for authentication.

Whenever session is out, you can simply redirect to Home/index from any .aspx.cs page by writing below code:

protected void Page_Load(object sender, EventArgs e)
   {
     if (Session["CurrentUser"] == null) {        
         Response.Redirect("/");
     }

   // other logics
   // ---
   // ---

   
  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文