SELECT * from LocalExport where (ISNULL(@SSO, '')='' OR SSO=@SSO) and (ISNULL(@SN, '')='' OR SN=@SN)
动态SQL语句
1 2 3 4 5 6 7 8 9 10
SET @SQL='select * from LocalExport where 1=1'; IF @SSO is not null BEGIN SET @SQL=@SQL+' AND SSO=@SSO' END IF @SN is not null BEGIN SET @SQL=@SQL+' AND SN=@SN' END EXEC sp_executesql @SQL
Internationalization is the process of designing and preparing your app to be usable in different languages. Localization is the process of translating your internationalized app into specific languages for particular locales.
Uncaught Error: It looks like your application or one of its dependencies is using i18n. Angular 9 introduced a global `$localize()` function that needs to be loaded. Please run `ng add @angular/localize` from the Angular CLI. (For non-CLI projects, add `import ‘@angular/localize/init’;` to your `polyfills.ts` file.
import { enableProdMode, TRANSLATIONS, TRANSLATIONS_FORMAT, MissingTranslationStrategy } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module'; import { environment } from './environments/environment';
if (environment.production) { enableProdMode(); }
// use the require method provided by webpack declare const require; // we use the webpack raw-loader to return the content as a string const translations = require('raw-loader!./locale/translate.fr.xlf').default;
在 ASP.NET Core 中,身份验证由 IAuthenticationService 负责,而它供身份验证中间件使用。
身份验证中间件
已注册的身份验证处理程序及其配置选项被称为“方案(schema)”。
Authentication schemes are specified by registering authentication services in Startup.ConfigureServices: 在startup.cs的ConfigureServices中通过注册身份认证,指定认证方案
User user = null; try { var authHeader = AuthenticationHeaderValue.Parse(Request.Headers["Authorization"]); var credentialBytes = Convert.FromBase64String(authHeader.Parameter); var credentials = Encoding.UTF8.GetString(credentialBytes).Split(new[] { ':' }, 2); var username = credentials[0]; var password = credentials[1]; user = await _userService.Authenticate(username, password); } catch { return AuthenticateResult.Fail("Invalid Authorization Header"); }
if (user == null) return AuthenticateResult.Fail("Invalid Username or Password");
var claims = new[] { new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()), new Claim(ClaimTypes.Name, user.Username), }; var identity = new ClaimsIdentity(claims, Scheme.Name); var principal = new ClaimsPrincipal(identity); var ticket = new AuthenticationTicket(principal, Scheme.Name);
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] public class MixedController : Controller .....
使用策略并指定授权方案 If you prefer to specify the desired schemes in policy, you can set the AuthenticationSchemes collection when adding your policy. 添加授权策略时设置AuthenticationSchemes列表,将对应的scheme添加进去
更新授权策略, 上面两种JWTBearer认证方案,将一个要注册到默认认证方案“JwtBearerDefaults.AuthenticationScheme”,另外的认证方案需要以唯一的方案注册(Only one JWT bearer authentication is registered with the default authentication scheme JwtBearerDefaults.AuthenticationScheme. Additional authentication has to be registered with a unique authentication scheme.)
1 2 3 4 5 6 7 8 9 10 11 12 13 14
public void ConfigureServices(IServiceCollection services) { // Code omitted for brevity
services.AddAuthorization(options => { var defaultAuthorizationPolicyBuilder = new AuthorizationPolicyBuilder( JwtBearerDefaults.AuthenticationScheme, "AzureAD"); defaultAuthorizationPolicyBuilder = defaultAuthorizationPolicyBuilder.RequireAuthenticatedUser(); options.DefaultPolicy = defaultAuthorizationPolicyBuilder.Build(); }); }
public class Startup { public void ConfigureServices(IServiceCollection services) { services.AddControllersWithViews(); services.AddDbContext<DataServiceContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DataServiceContext"))); }
public void Configure(IApplicationBuilder app) { app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseMvc(); } }
// GET: Products/Details/5 public async Task<IActionResult> Details(string id) { if (id == null) { return NotFound(); }
var product = await _context.ProductData .FirstOrDefaultAsync(m => m.Id == id); if (product == null) { return NotFound(); }
return View(product); }
// GET: Products/Create public IActionResult Create() { return View(); }
// POST: Products/Create // To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see http://go.microsoft.com/fwlink/?LinkId=317598. [HttpPost] [ValidateAntiForgeryToken] public async Task<IActionResult> Create([Bind("Id,SN,Brand,CreateTime,ProductName,Restriction")] Product product) { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return RedirectToAction(nameof(Index)); } return View(product); }
// GET: Products/Edit/5 public async Task<IActionResult> Edit(string id) { if (id == null) { return NotFound(); }
var product = await _context.ProductData.FindAsync(id); if (product == null) { return NotFound(); } return View(product); }
// POST: Products/Edit/5 // To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see http://go.microsoft.com/fwlink/?LinkId=317598. [HttpPost] [ValidateAntiForgeryToken] public async Task<IActionResult> Edit(string id, [Bind("Id,SN,Brand,CreateTime,ProductName,Restriction")] Product product) { if (id != product.Id) { return NotFound(); }
issue: The entity type ‘XXModel’ requires a primary key to be defined.
Model类型需标注主键
1 2 3 4 5 6
private Guid _id; [Key] public Guid ID { get { return _id; } }
issue “No context type was found in the assembly ‘MyServices.Models’.” 在多项目解决方案中,执行Migration的是Models项目,读取Startup中的context配置, 检查Startup.cs的addDbContext配置 另有命令
issue “The type ‘xxContext’ does not inherit from DbContext. The DbMigrationsConfiguration.ContextType property must be set to a type that inherits from DbContext.” 解决方法是在startup项目安装 Microsoft.EntityFrameworkCore.Tools
一般只需要.Net6即可,在 OS 特定的 TargetFramework 的末尾指定可选的 OS 版本,例如,net6.0-ios15.0。 版本指示应用或库可用的 API。 它不控制应用或库在运行时支持的 OS 版本。 它用于选择项目编译的引用程序集,并用于从 NuGet 包中选择资产。 将此版本视为“平台版本”或“OS API 版本”,可以与运行时 OS 版本进行区分。
There is also a built-in environment variable called NODE_ENV. You can read it from process.env.NODE_ENV. When you run npm start, it is always equal to ‘development’, when you run npm test it is always equal to ‘test’, and when you run npm run build to make a production bundle, it is always equal to ‘production’. You cannot override NODE_ENV manually. This prevents developers from accidentally deploying a slow development build to production. ————《create-react-app自定义环境变量》
##Step 1 - Add relevant dependencies ng add @angular-eslint/schematics ##Step 2 - Run the convert-tslint-to-eslint schematic on a project ng g @angular-eslint/schematics:convert-tslint-to-eslint {{YOUR_PROJECT_NAME_GOES_HERE}} ##Step 3 - Remove root TSLint configuration and use only ESLint