我有自定义全局错误处理程序
@Injectable()
export class GlobalErrorHandler implements ErrorHandler {
constructor(private injector: Injector) {
}
handleError(err: any): void {
var route = this.injector.get(Router);
var snackBar = this.injector.get(MatSnackBar);
console.log(err);
if (err instanceof HttpErrorResponse) {
var message = ErrorMessages.get(err.status);
if (route.url.toLowerCase() !== '/login' && err.status === 401) {
route.navigateByUrl('/login');
}
if (message.length > 0) {
snackBar.open(message, "x", { duration: 5000, horizontalPosition: "center", verticalPosition: "bottom" });
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
小吃店的位置不是垂直底部和水平居中.
如果我在http拦截器中使用snackbar,它会正确显示
@Injectable()
export class AuthHttpInterceptor implements HttpInterceptor {
constructor(private loginService: LoginService, private …Run Code Online (Sandbox Code Playgroud) 我想创建一个验证不同输入的类.
在Controller中,我有一个简单的ActionResult方法类型.
public ActionResult Detail( int? id ) {
ViewData["value"] = _something.GetValueById( id );
return View();
}
Run Code Online (Sandbox Code Playgroud)
如果导航到http://localhost/Home/Detail/3那么控制器将返回View,其中它显示来自model的id(它是整数)的可用值.
如果ID为null,则控制器将我重定向到所有值.
如果将ID路由(如http://localhost/Home/Detail/3fx)更改为不同的数据类型,则控制器将返回红色页面.(除外)
我想检查ID是否为int以避免红页错误(带有例外列表).
我看到这isNaN只是双数据类型.
对不起,如果我的问题很烦人.
我创建了一个保存文件的控制器.
以下代码是该控制器的一部分:
if ( Request.Files.Count != 0 ) {
HttpFileCollectionBase files = Request.Files;
foreach ( HttpPostedFileBase file in files ) {
if ( file.ContentLength > 0 ) {
if ( !file.ContentType.Equals( "image/vnd.dwg" ) ) {
return RedirectToAction( "List" );
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在ASPX页面很简单:
<input type="file" name="file" />
<input type="file" name="file" />
...// many inputs type file
Run Code Online (Sandbox Code Playgroud)
问题是foreach因为它返回一个错误(我知道因为我在调试模式下运行并在foreach语句中放置了断点):
Unable to cast object of type 'System.String' to type 'System.Web.HttpPostedFileBase'.
Run Code Online (Sandbox Code Playgroud)
我的错是什么?
我在javascript中有这两个日期时间变量:
first_date = Date.parse('05/21/2012 0:00:00 ');
second_date = Date.today();
Run Code Online (Sandbox Code Playgroud)
如果我正在使用(http://code.google.com/p/datejs/wiki/APIDocumentation#compareTo)
return first_date.compareTo(second_date)
Run Code Online (Sandbox Code Playgroud)
然后发生异常:
Object function Date() { [native code] } has no method 'compareTo' 在谷歌浏览器中.
我正在使用http://www.datejs.com/的最新版Date.js
如何解决这个问题?
我会提到其他函数(add(-5).days(),today()等)工作正常.
PS:我在这里看了一下(http://code.google.com/p/datejs/issues/detail?id=129),但没有解决方法.
我有一个示例代码
aCommand.CommandType = CommandType.StoredProcedure;
aCommand.Parameters.AddWithValue("@book_id", bookID);
aCommand.Parameters.AddWithValue("@user_id", userID);
Run Code Online (Sandbox Code Playgroud)
之后我想用以下方法执行一个简单的查询CommandText:
aCommand.CommandText = "SELECT * FROM aTABLE";
aCommand.ExecuteNonQuery();
Run Code Online (Sandbox Code Playgroud)
但是错误发生了:
例外:找不到存储过程'SELECT*FROM aTABLE'
在这种情况下,我必须创建一个新的SqlCommand对象实例?
这是一种使用同一个SqlCommand对象来避免创建一个的方法吗?
也许这个问题应该很容易,但事实并非如此.我在ASP.NET中阅读了使用System.Web.Caching.Cache类的问题.
我有一个单身人士课程:
private System.Web.Caching.Cache _cache;
private static CacheModel _instance = null;
private CacheModel() {
_cache = new Cache();
}
public static CacheModel Instance {
get {
return _instance ?? new CacheModel();
}
}
public void SetCache(string key, object value){
_cache.Insert(key, value);
}
Run Code Online (Sandbox Code Playgroud)
如果,在我的代码中的任何其他位置,我调用以下内容:
CacheModel aCache = CacheModel.Instance;
aCache.SetCache("mykey", new string[2]{"Val1", "Val2"}); //this line throws null exception
Run Code Online (Sandbox Code Playgroud)
为什么第二行抛出空引用异常?
也许我在代码的某个地方犯了一些错误?
谢谢.
我阅读并尝试了一些代码
在Windows中删除大文件夹的最快方法是什么?(rmdir /s /q folder)
我想创建一个删除名称以其开头的文件夹的批处理Test_.我有一个文件夹D:\Test_123_19_10_2012.
如何在批处理或命令提示符下写?需要正则表达式?
谢谢你的耐心等待.
我有以下代码:
Action<CancellationToken> act1 = tk1 => {
//sleep for 5 seconds
Console.WriteLine(...);
};
Task t1 = new Task(() => execute(act1));
t1.Start();
Run Code Online (Sandbox Code Playgroud)
怎样睡觉里面行动?我尝试过:
Thread.Sleep(TimeSpan.FromSeconds(5));
Run Code Online (Sandbox Code Playgroud)
和
Task.Delay(TimeSpan.FromSeconds(5));
Run Code Online (Sandbox Code Playgroud) 让我们假设下载所选文件的控制器:
public FileResult Download( string f ) {
Stream file = MyModel.DownloadFiles( f );
return File( file, "application/octet-stream", (file as FileStream).Name );
}
Run Code Online (Sandbox Code Playgroud)
和MyModel包含
public static Stream DownloadFiles(string file){
return new FileStream(file, FileMode.Open, FileAccess.Read);
}
Run Code Online (Sandbox Code Playgroud)
如果我using在控制器中使用关键字,那么将抛出异常:Cannot access closed file.
好吧,我想确保下载的文件将被处理(我不知道是否可能,如何做到)或不?
谢谢
我创建了 Blazor 服务器 Web 应用程序,并将其部署在 Azure 应用服务上,在Network选项卡中我看到大量请求,https://mywebsites0123.azurewebsites.net/_blazor?id=3OO-T6L4Bu9bMRF8QAo_5Q&_=166722导致应用程序不稳定。
在本地主机(调试和发布)上,我找不到任何请求,并且应用程序运行顺利。
我读了这篇C# Blazor 服务器 - 为什么有这么多 _blazor 请求和如此多的内存消耗?但找不到解决方案。
启动页面如下所示:
ConfigureServices(IServiceCollection services)
services.AddRazorPages();
services.AddServerSideBlazor().AddMicrosoftIdentityConsentHandler();
services.AddSignalR(e =>
{
e.MaximumReceiveMessageSize = 2000 * 1024;
});
// Radzen init
services.AddScoped<DialogService>();
services.AddScoped<TooltipService>();
services.AddScoped<NotificationService>();
services.AddMemoryCache();
var apiScope = Configuration["Authentication:ApiScope"];
services.AddMicrosoftIdentityWebAppAuthentication(Configuration, "Authentication:AzureAd")
.EnableTokenAcquisitionToCallDownstreamApi(new string[] { apiScope })
.AddInMemoryTokenCaches();
services.AddControllersWithViews().AddMicrosoftIdentityUI();
services.AddAuthorization();
Run Code Online (Sandbox Code Playgroud)
和
Configure(IApplicationBuilder app, IWebHostEnvironment env)
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers(); …Run Code Online (Sandbox Code Playgroud) c# ×7
.net ×1
angular ×1
asp.net ×1
asp.net-mvc ×1
batch-file ×1
blazor ×1
caching ×1
command ×1
data-caching ×1
datejs ×1
javascript ×1
sql-server ×1
stream ×1
t-sql ×1