asp.net简单数据工厂 ------使用方法

引用dll文件

在web.config进行配置

 

< appSettings >
    
        
<!--
        连接Sql数据库
        <add key="provider" value="SqlProvider"/>
        <add key="conn" value="server=.;database=Test;uid=sa;pwd=sa"/>
        
-->
        
<!--  连Access数据库  -->
        
< add  key ="provider"  value ="OdbcProvider" />
        
< add  key ="conn"  value ="Provider=Microsoft.Jet.OleDb.4.0;Data Source=E:wwwTestClassTest.mdb;Persist Security Info=True;" />

    
</ appSettings >

 数据绑定

 

private   void  Bind()
        
{
            ICommonAccess com
=(ICommonAccess)DataFactory.GetCommonAccess();
            DataSet ds
=new DataSet();
            ds
=com.GetDs("select * from userinfo","de");
            
this.DataGrid1.DataSource=ds;
            
this.DataGrid1.DataBind();
        }

 

增,删,改

 

private   void  Button1_Click( object  sender, System.EventArgs e)
        
{
                                                                ICommonAccess com
=(ICommonAccess)DataFactory.GetCommonAccess();
            
string str=com.GetExCmd("insert into userinfo(uname,sex) values ('"+this.TextBox2.Text+"','"+this.TextBox3.Text+"')");
            Page.RegisterStartupScript(
"","<script>alert('"+str+"')</script>");
        }

 

用户登陆

 

private   void  Button2_Click( object  sender, System.EventArgs e)
        
{
                                                                ICommonAccess com
=(ICommonAccess)DataFactory.GetCommonAccess();
            
int i=com.GetSearch("select count(*) from userinfo where uname='"+this.TextBox2.Text+"'");
            
this.TextBox1.Text=""+i;
        }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ASP.NET Core 提供了内置的身份验证和授权功能,可以轻松地实现用户的登录和登出功能。 要实现登录功能,首先需要在 ConfigureServices 方法中添加身份验证服务: ```csharp services.AddAuthentication(options => { options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.DefaultChallengeScheme = GoogleDefaults.AuthenticationScheme; }) .AddCookie(options => { options.LoginPath = "/Account/Login/"; options.LogoutPath = "/Account/Logout/"; }) .AddGoogle(options => { options.ClientId = Configuration["Authentication:Google:ClientId"]; options.ClientSecret = Configuration["Authentication:Google:ClientSecret"]; }); ``` 上面的代码中,我们添加了 Cookie 身份验证服务,并指定了登录和登出的路径。同时,我们还添加了 Google 身份验证服务,并设置了 ClientId 和 ClientSecret。 接着,在 Configure 方法中启用身份验证中间件: ```csharp app.UseAuthentication(); ``` 现在,我们可以在 AccountController 中添加 Login 和 Logout 的动作方法: ```csharp public IActionResult Login(string returnUrl = "/") { ViewData["ReturnUrl"] = returnUrl; return View(); } [HttpPost] public async Task<IActionResult> Login(LoginViewModel model, string returnUrl = "/") { if (ModelState.IsValid) { var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure: false); if (result.Succeeded) { _logger.LogInformation("User logged in."); return RedirectToLocal(returnUrl); } if (result.RequiresTwoFactor) { return RedirectToAction(nameof(LoginWith2fa), new { returnUrl, model.RememberMe }); } if (result.IsLockedOut) { _logger.LogWarning("User account locked out."); return RedirectToAction(nameof(Lockout)); } else { ModelState.AddModelError(string.Empty, "Invalid login attempt."); return View(model); } } // If we got this far, something failed, redisplay form return View(model); } [HttpPost] public async Task<IActionResult> Logout() { await _signInManager.SignOutAsync(); _logger.LogInformation("User logged out."); return RedirectToAction(nameof(HomeController.Index), "Home"); } ``` 上面的代码中,我们首先添加了一个 Get 请求的 Login 方法,用于显示登录页面。接着,我们添加了一个 Post 请求的 Login 方法,用于处理用户提交的登录表单。在这个方法中,我们调用了 _signInManager.PasswordSignInAsync 方法进行身份验证,并根据不同的结果进行相应的处理。最后,我们还添加了一个 Logout 方法,用于处理用户的登出请求。 现在,我们只需要在视图中添加相应的表单,就可以实现登录和登出功能了: ```html <form asp-action="Login" asp-route-returnUrl="@ViewData["ReturnUrl"]" method="post"> <div class="form-group"> <label asp-for="Email"></label> <input asp-for="Email" class="form-control" /> <span asp-validation-for="Email" class="text-danger"></span> </div> <div class="form-group"> <label asp-for="Password"></label> <input asp-for="Password" class="form-control" /> <span asp-validation-for="Password" class="text-danger"></span> </div> <div class="form-group"> <div class="checkbox"> <label asp-for="RememberMe"> <input asp-for="RememberMe" /> @Html.DisplayNameFor(m => m.RememberMe) </label> </div> </div> <div class="form-group"> <button type="submit" class="btn btn-primary">Login</button> </div> </form> <a asp-action="Logout" asp-controller="Account">Logout</a> ``` 上面的代码中,我们添加了一个登录表单和一个登出链接,用于演示登录和登出功能。其中,登录表单使用了 asp-for 和 asp-validation-for 标签帮助器,可以自动生成相应的 HTML 元素和验证信息。登出链接使用了 asp-action 和 asp-controller 标签帮助器,可以自动生成相应的 URL。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值