我有ASP.NET CORE C#项目.
我想更改我的解决方案名称和整个项目的名称.
例如 :
OldSolution.OldName // this is Solution
OldSolution.OldName.Project1
OldSolution.OldName.Project2
OldSolution.OldName.Project3
Run Code Online (Sandbox Code Playgroud)
至
ChangedName.NewName // this is solution
ChangedName.NewName.Project1
ChangedName.NewName.Project2
ChangedName.NewName.Project3
Run Code Online (Sandbox Code Playgroud)
更改所有名称空间,引用其他项目的项目名称(当我查看项目的引用时,引用的项目仍然是相同的名称.它们尚未更改.)
我能这样做吗?
AuthenticationRequiredAttribute类
public class AuthenticationRequiredAttribute : ActionFilterAttribute
{
ILoginTokenKeyApi _loginTokenKeyApi;
IMemoryCache _memoryCache;
public AuthenticationRequiredAttribute(IMemoryCache memoryCache)
{
_memoryCache = memoryCache;
_loginTokenKeyApi = new LoginTokenKeyController(new UnitOfWork());
}
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var memory = _memoryCache.Get(Constants.KEYNAME_FOR_AUTHENTICATED_PAGES);
string requestedPath = filterContext.HttpContext.Request.Path;
string tokenKey = filterContext.HttpContext.Session.GetString("TokenKey")?.ToString();
bool? isLoggedIn = _loginTokenKeyApi.IsLoggedInByTokenKey(tokenKey).Data;
if (isLoggedIn == null ||
!((bool)isLoggedIn) ||
!Constants.AUTHENTICATED_PAGES_FOR_NORMAL_USERS.Contains(requestedPath))
{
filterContext.Result = new JsonResult(new { HttpStatusCode.Unauthorized });
}
}
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
}
}
Run Code Online (Sandbox Code Playgroud)
HomeController的
public class HomeController : Controller
{
IUserApi …Run Code Online (Sandbox Code Playgroud) 我在解决方案中只有一个类库.该库将作为NuGet包发布.
所以,我想将库添加到我的项目中,我必须连接项目的启动来定义:
services.AddDbContext<DataContext>(options =>
options.UseSqlServer(Configuration["ConnectionStrings:LocalConnectionString"]));
Run Code Online (Sandbox Code Playgroud)
但我的类库项目中没有启动.如何在库项目中为我的实际项目定义它?
我想每次都触发 OnModelCreating new DataContext(new Entity())......但是当我创建一个表的连接时,它可以工作。当为另一个表创建连接时,OnModelCreating 不再工作,所以因为我出错了,
the entity type <tableName> is not part of the model for the current context.
public class DataContext : DbContext
{
private BaseEntity _entity;
public DataContext(BaseEntity entity)
{
Database.Connection.ConnectionString = Parameters.ConnectionString;
_entity = entity;
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
_entity.Map(modelBuilder); // this is dynamic fluent api here
}
}
Run Code Online (Sandbox Code Playgroud) 我已将依赖注入添加到项目中。但是当我使用new关键字创建实例时,依赖注入不起作用。
public class MyClass
{
ILoginTokenKeyApi _loginTokenKeyApi;
public MyClass(ILoginTokenKeyApi loginTokenKeyApi)
{
_loginTokenKeyApi = loginTokenKeyApi;
}
...
}
Run Code Online (Sandbox Code Playgroud)
当我尝试创建 MyClass 的实例时,它希望自然构造一个参数。
像这样 :
MyClass mc = new MyClass(); // ERROR, it wants a parameter (but it is what i want)
Run Code Online (Sandbox Code Playgroud)
我要做 :
MyClass mc = new MyClass(new LoginTokenKeyClass()); // this is not a good code for me
Run Code Online (Sandbox Code Playgroud)
我如何创建没有参数的 MyClass 实例,因为它注入了依赖项。
c# asp.net dependency-injection parameter-passing asp.net-core
我的目标是:当点击链接时,'auth/login/:tokenKey'将触发一个方法,然后重定向 A 或 B 组件。对于此链接'auth/login/:tokenKey',不需要组件。它应该只是 ts 文件中的一个方法。
怎么做 ?
canActivate(route: ActivatedRouteSnapshot) {
localStorage.setItem('token_key', route.params.tokenKey);
return true;
}
Run Code Online (Sandbox Code Playgroud)
我不需要使用'auth/login/:tokenKey'路径组件。在该路径中,将运行一个进程,然后将被重定向到索引页面。
但是当我使用“redirectTo”指令时,Guard 不起作用。
当我与组件一起使用时,Guard 可以工作。
没有组件如何使用guard?
const routes: Routes = [
{ path: '', component: IndexComponent },
{ path: 'auth/login', component: LoginComponent },
{ path: 'auth/login/:tokenKey',
canActivate: [GetTokenKeyGuard],
redirectTo: '' }, //........................ Guard doesnt work.
{ path: 'auth/login/:tokenKey',
canActivate: [GetTokenKeyGuard],
component: LoginComponent }, //............. Guard works.
];
Run Code Online (Sandbox Code Playgroud) <div [innerHTML]="'<b>HEY</b>'"></div>
Run Code Online (Sandbox Code Playgroud)
效果很好!但问题是我不希望将div或任何其他元素添加到页面中。我只想将innerHTML 内容呈现到页面。我试过ng-container而不是,div但它不起作用。我怎样才能让它发生?
export interface Principal {
name: string; // just a field
[attribute: string]: any; // allowed custom fields
[securityId]: string; // what does this mean ?
}
Run Code Online (Sandbox Code Playgroud)
securityId 是什么意思?
我想查询一个id在顶部,其他正常优先级.
例如:ID 5位于顶部,其他正常订购.
ID Name
-----------
5 Michael
1 A
2 B
3 C
4 D
6 E
Run Code Online (Sandbox Code Playgroud)
MS SQL中的查询是什么?
https://loopback.io/doc/en/lb4/HasMany-relation.html
我按照此步骤操作,然后尝试获取数据,include但得到 500。
500 Error: Invalid "filter.include" entries: {"relation":"ranks"}
Run Code Online (Sandbox Code Playgroud)
我想要的是获得具有相关等级的游戏对象。
排名模型
import { Entity, model, property, belongsTo } from '@loopback/repository';
import { Game, GameWithRelations } from './game.model';
@model({ settings: { strict: 'filter' } })
export class Rank extends Entity {
@property({
type: 'string',
id: true,
})
id?: string;
@property({
type: 'string',
})
name?: string;
@property({
type: 'string',
})
shortName?: string;
@property({
type: 'string',
})
avatar?: string;
@belongsTo(() => Game)
gameId: string;
constructor(data?: Partial<Rank>) {
super(data);
}
}
export …Run Code Online (Sandbox Code Playgroud) 我想从扩展控制器类轻松获取我的方法,并向控制器类添加一些方法以在所有其他控制器中使用,如下所示:
扩大
public string GetString()
{
return "iamanexample";
}
Run Code Online (Sandbox Code Playgroud)
认证控制器
public class AuthenticationController : Controller
{
public IActionResult Index()
{
string getMyStr = GetString();
return View();
}
}
Run Code Online (Sandbox Code Playgroud)
我是否必须创建一个由控制器类继承的自定义类并在其中添加我的方法,然后使用我的自定义控制器类?或者还有其他解决方案吗?
c# ×6
asp.net ×4
asp.net-core ×4
angular ×2
javascript ×2
typescript ×2
.net ×1
dom ×1
html ×1
loopback4 ×1
loopbackjs ×1
memorycache ×1
mongodb ×1
node.js ×1
sql ×1
sql-server ×1
t-sql ×1
unit-of-work ×1